REST
easy 26 minREST is a style for network APIs: everything worth naming gets an address, and a small shared set of HTTP methods acts on it.
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
Your labels, everyone's handles.
A wall of labelled compartments with the same four handles on each: look, new, swap, empty. Learn the handles once and every door works.
Cheat sheet
- Safe
- GET, HEAD, OPTIONS, QUERY
- Idempotent
- safe ones, PUT, DELETE
- Create
- POST, 201, Location
- Lost update
- ETag, If-Match, 412
- Safe create
- Idempotency-Key
- Errors
- problem+json, RFC 9457
- Contract
- OpenAPI 3.2
- Retire
- Deprecation, Sunset, 410
- Limit
- 429, Retry-After
Spot it when you see
- A public API for many languages.
- Reads that a CDN can keep.
- Plain create, read, update and delete.
- Clients you do not control.
Tricks that stick
- Nouns in the path, verbs in the method.
- Four means you, five means us.
- PUT is the whole, PATCH is a piece.
- Idempotent is about the state, not the answer.
Do not forget
- Writing on a GET.
- 200 with an error inside.
- Lists without a limit.
- POST retried without a key.
- Tokens in URLs.