REST (Representational State Transfer)
200 Ok
HTTP status in response.304 Not Modified
HTTP status in response.We only need 2 base URLs per resource
/cars
)/cars/1244
)4 operations (CRUD)
/cars
: create a new car/cars/1244
: create a new car with id 1244
or fail/cars
: list cars/cars/1244
: show car 1244/cars
: replace cars/cars/1244
: if exists update car 1244, if not, create car 1244 or fail/cars
: delete all cars/cars/1244
: delete car 1244Avoid verbs to name your resources. Use plural nouns.
Use verbs only if the functionality provided by the call is an operation and not a resource, such as:
Be consistent
Use concrete resource names instead of abstract ones. e.g., /cars
, /cats
accept: application/header
Few examples how respose format:
?alt=json
\venue.json
Accept: application/json
or ?type=json
?offset=10&limit=50
limit=10&offset=0
Few examples of pagination:
?offset=10&limit=50
?offset=10&limit=50
?start=10&count=50
200 201 304 400 401 403 404 500
{
"code": 23213,
"message": "MESSAGE",
"info": "https://SOME_DOMAIN/docs/error/CODE"
}
Examples by different orgs:
{
"type": "OAuthExeption",
"message": "----"
}
Twillo
{
"status": 401,
"message" "",
"code": 20003,
"more_info": "http://twillo.com/docs/erros/20003"
}
Assosiations used to represent relationships between entities
POST `/owners/1234/cars`
GET `/owners/1234/cars/1244`
?
in the query string
GET /cars?color=red&location=newyork
/v1/cars
Examples by different orgs:
/2010-04-01/Accounts
/services/data/v20.0/subjects/account
/?v=1.0
/v1
/v2
/v1
/cars?fields=name,color,regitryLocation.postalCode
Examples by different orgs:
/people:(id,first-name,last-name,industry)
/joe.smith/friends?fields=id,name,picture
?fields=title,media:group(media:thumbnail)
/search?q=short+hair
/cars?q=red+color
/search?q=red-color&scope=cars,owners
api.domain.com
developers.domain.com
Examples by different orgs:
api.foursquare.com
developers.foursquare.com
api.twitter.com
search.twitter.com
stream.twitter.com
dev.twitter.com
graph.facebook.com
api.facebook.com
developers.facebook.com
Examples by different orgs: