24. HTTP methods
GET POST PUT DELETE HEAD PATCH ...
Also called “Verbs”
Together with a URI they tell the API what to do
25. GET retrieve a resource representation
HEAD get only the headers, no body
PUT update a resource
POST create a resource, execute controllers
DELETE remove a resource
PATCH partially update a resource
more...
27. Metadata
Useful req/res information in the headers
Content-Type Cache-Control
Content-Length Expires
Last-Modified Date
Etag Pragma
Location Custom, ...
28. Metadata
Useful req/res information in the headers
Content-Type Cache-Control
Content-Length Expires
ER
LAT
AT Date
Last-Modified E ON TH
Etag M OR Pragma
Location Custom, ...
30. Versioning
APIs should evolve without breaking
example.com/api/v3/posts BAD
v3.api.example.com/posts OK
Accept: application/vnd.example.v3+json GOOD
31. Pagination
Return a partial collection
example.com/posts/pages/2 BAD
example.com/posts?page=2&per_page=20 GOOD
45. application caching
don’t do things twice
Never calculate things twice. Do it once, store it.
Redis, Memcached, I’m looking at you.
46. HTTP caching
save bandwidth, cut response time
Use HTTP headers to define the response’s
cacheability, expiration, validity, ...
Take advantage of Varnish, Squid, ...
47. database replication
faster reads is a big win
If your API serves more reads than writes, send the
reads to read-only slaves of the database