Things you should know
Building a
Public API
}During
Before
After
@yonatanm
Outbrain
Outbrain
0.5B> 190B
Unique Visitors RecommendationS
per Month
“Boss, Boss
hi API i not RESTful”
* min {control on usage}
* max {responsibility}
* decisions.exist {_.takeAtDay1}
* min {control on usage}
* max {responsibility}
* decisions.exist {_.takeAtDay1}
Be Pragmatic
Make reasonable
compromise
Quiz #1
???
Product
API
Users
Answer
Developers
Product
API
Users
Quiz #2
???
Product
API
U.X.
Answer
Product
API Resources
&& URIS
U.X.
Be consistently
consistent
* HTTP methods
* HTTP codes
* Headers
* Authentication
No one likes surprises
Make your users feel at home
Use Standards:
Error handling
It is all about the
Expectations
GET
POST
PUT
/customers/{id}
/customers
/customers
REQUEST RESPONSE
customerGET
customercustomer
customercustomer*
200
201
200
To embed
GET /customers/1
GET /customer/1/orders
|| !to embed
GET /customers/1
Can we have both ?
To embed || !to embed ?
Simple
All you need in one request
Fewer transactions
Simple
All you need in one request
Fewer transactions
Fast
Building block
flexibility
Cacheable
Fast
Building block
flexibility
Cacheable
!to embed
to embed
and do it right ?
*
Yes We Can !
GET /customers/1
GET /customers/1?embed=orders
Yes We Can #2
GET /customers/1
Quiz #3
???
Product
API
U.I.
Answer
Documentation
Product
API
U.I.
Documentation
apiary.io
Swager
Mashape and More...
apiary.io
Swager
Mashape and More...
* Be consistent
* Focus on Resources
* Less > More
* Examples
* Be consistent
* Focus on Resources
* Less > More
* Examples
‫במקביל‬ ‫עבודה‬ "
”‫דביל‬ ‫לכל‬ ‫הצלחה‬ –
‫במקביל‬ ‫עבודה‬ "
”‫דביל‬ ‫לכל‬ ‫הצלחה‬ –
** Sand-box ? +1** Sand-box ? +1
Documentation
Documentation
Documentation
* UX – interactions
* UI – documentation
* Ideas to new features
* Bugs
Eat your own dog food
Tip #1
Tip #2
What's wrong with using DB IDs
as your entity IDs?
GET /customers/1
“Authorization”
“privacy” , your privacy
“Authorization”
“privacy” , your privacy
Bi Directional mapping using secret key-
HOW?
Tip #2
Add another column in the DB
27847321845691
Like a version
OR
/SUPPORT/multiple/VERSIONS/v2.5/
/SELL/your/soul/to/backwards/compatibility
URI should control
identity not presentation
http://bit.ly/1Mo0yXF
===>
GET /customer/1 HTTP/1.1
Accept: application/outbrain.customer-v2.5+json
===>
GET /customer/1 HTTP/1.1
Accept: application/outbrain.customer-v2.5+json
<===
HTTP/1.1 200 OK
Content-Type: application/outbrain.customer-v2.5+json
<===
HTTP/1.1 200 OK
Content-Type: application/outbrain.customer-v2.5+json
Like a version
– One ?
– Three ?
– Four ?
– One ?
– Three ?
– Four ?
Quiz #3
How many Types do you need ?
GET /customer/1
PUT /customer/1POST /customer/1
Clones ? Not Really !
!= Internal Model
Retrieve != Update != Create
JSON 2 Case Class [Scala]
http://json2caseclass.cleverapps.io/http://json2caseclass.cleverapps.io/
.json
.scala
3
Security
Tip #3
Translation
1
2
WebWeb
Business Logic (API)
4
5
6
Events
Cache
Much more to talk about
* Security
* Internal and Public API
* Rate Limit
* Testing
* Rest maturity model
* Security
* Internal and Public API
* Rate Limit
* Testing
* Rest maturity model
Q ? A !
Thank You

Developing a Public API -- at Reversim Summit 2015