@simonrenoult | srenoult@octo.com
GET /people?first_name=John
> 200 OK
[{
"id":"007",
"first_name": "John",
"last_name": "Lennon",
"age": 76,
"gender": "M",
"albums": "/v1/people/007/albums"
}]GET
POST
PUT
DELETE
PATCH
Read something. No side-effect.
Create something.
Update or create something.
Remove something.
Update (partially) something.
Verbs?
No, HTTP takes care of that
Resource
We manipulate (HTTP verb) a resource (noun)
CamelCase
Snake_case
Spinal-case
GET /v1/orders?userId=007
GET /v1/orders?user_id=007
GET /v1/orders?user-id=007
/client
Nop.
/clients
Yes!
In the headers
As a query parameter
In the URL path
Nop!
Meh...
Yes!
200
201
204
206
OK
Created
No content
Partial content
GET /pokemons
POST /pokemons
DELETE /pokemons
GET /pokemons
400
401
403
404
Bad request
Unauthorized
Forbidden
Not Found
500
503
Internal Server Error
Service Unavailable
GET /v1/products/search?name=la*GET /v1/products?range=0-24GET /v1/products?sort=foo&desc=barGET /clients/007?fields=name,address(street)POST
Verbs
Manipulate actions instead of resources
Stay RESTful-ish. POST is :
Search cross-resource
Activate or deactivate something
Send a password recovery email
POST /v1/search
Make it RESTful. You can do it.
POST /v1/recovery-email
Don't be RESTful at any price.
Be affordable first.
HAL
Hydra
JSON-LD
RFC5988
New kid in the block
Define a set of "standard" link
Cool kid in the block
Yet another kid in the block
Up to you guys...
Don't use business specific terms
One way to do things
Design for your clients, not your data
Design for the many, allow the few (80-20)
Not too big. Not too thin.
One URL, one resource
GET /clients/007
{
"id":"007",
"name":"Bond",
"address":"/v1/addresses/362"
}
GET /addresses/362
{
"id":"123",
"street":"Avenue des Champs-Elysées",
"country": "/v1/countries/839"
}
One URL, one content
GET /clients/007
{
"id":"007",
"name":"Bond",
"address": {
"street-number":"50",
"street":"Avenue des Champs-Elysées,
"country:"france"
},
"articles": [{
"id":"ab3423fds",
"name":"foo",
"description":"foo bar"
}],
"comments":[{
...
}],
"private-messages":[{
...
}]
}
HTTPS everything
OAuth2/OIDC no matter what
https://api.fakecompany.com
https://api.sandbox.fakecompany.com
https://developers.fakecompany.com
https://oauth2.fakecompany.com
https://oauth2.sandbox.fakecompany.com
Curl
Swagger
Always provide curl samples
Open API Spec. (fev 2016)
Use HTTP.
Be affordant.
Ship it.
Questions?
Thanks.
http://vinaysahni.com/best-practices-for-a-pragmatic-restful-api
https://httpstatuses.com/
http://blog.octo.com/designer-une-api-rest