Q&A-1What is REST, and what do most so-called REST APIs actually implement?
Answer
The 90-second answer. REST is Roy Fielding's architectural style, defined in chapter 5 of his 2000 dissertation. Six constraints: client–server, stateless, cacheable, uniform interface, layered system, and code-on-demand. The last being the only optional one. The uniform interface has four parts: resources identified in the request, manipulation through representations, self-descriptive messages, and hypermedia as the engine of application state.
Most APIs that call themselves REST satisfy the first five loosely and drop hypermedia entirely. Leonard Richardson's maturity model (a 2008 QCon talk, written up by Martin Fowler in 2010) names the levels, and the overwhelming majority of public APIs sit at level 2:
| Level | Shape | Examples |
|---|---|---|
| 0 | One URL, one verb, action in the body | SOAP, XML-RPC |
| 1 | Many URLs, still POST for everything | /getUser?id=7 |
| 2 | Resources + HTTP verbs + status codes | GitHub, Stripe, most public APIs |
| 3 | Level 2 + links that drive transitions | GitHub's Link header pagination; HAL, JSON:API |
So the honest answer is: what most people build is HTTP + JSON RPC with resource-shaped URLs. That is a defensible engineering choice, but only if you know which constraints you dropped.
Two exchanges that show what the dropped constraints buy you.
Conditional GET, which only works because GET is safe and responses are self-descriptive:
GET /v1/charges/ch_3Px HTTP/1.1
Host: api.example.com
If-None-Match: "a1b2c3"
HTTP/1.1 304 Not Modified
ETag: "a1b2c3"
Cache-Control: private, max-age=60The server compares the tag, finds the representation unchanged, and returns headers with no body. A 304 is a few hundred bytes of headers against a 40 KB JSON body: call it 99% of the bytes saved on a cache hit. That is the cacheability constraint paying rent.
Idempotent retry, which only works because the client can safely repeat the request:
POST /v1/charges HTTP/1.1
Idempotency-Key: 7f3c9a41-...
HTTP/1.1 201 Created
Location: /v1/charges/ch_3PxThe client times out before reading the response and retries with the same key. The server finds the stored response for that key and replays the same 201 and the same body; no second charge is created. Stripe documents this behaviour and a 24-hour retention window for keys. There is an IETF draft, draft-ietf-httpapi-idempotency-key-header, standardising the header: a draft, not an RFC.
Failure modes, and how you see them.
- Retrying a POST that is neither safe nor idempotent double-charges. You detect it as duplicate rows or duplicate charges with near-identical timestamps, and fix it with an idempotency key.
- Using POST for reads makes the response uncacheable by any intermediary and unsafe to retry after a timeout. Detection: cache hit ratio near zero on endpoints that are read-only.
- Returning
200 OKwith{"error": ...}in the body means every proxy, retry library and dashboard reads failure as success. Detection: your error-rate graph says 0% while support tickets say otherwise. Use the codes as defined in RFC 9110:201withLocation,204,304,409,412,429withRetry-After,503withRetry-After. - Keeping client session state on the server breaks statelessness: a request that lands on another instance fails, so you add sticky sessions, and rolling deploys start dropping user sessions.
When full hypermedia is worth it. Long-lived public APIs with clients you do not control, where you want to add transitions without breaking callers. When one front end ships alongside the API, links in payloads are mostly ceremony.
The practical core: model resources, use HTTP semantics as defined rather than as convention, and keep no client session state on the server. An action endpoint where a noun would be contorted is fine, not knowing which constraint you dropped is not, because the bill arrives later as an API that cannot be cached, cannot be retried safely, or reports failures as successes.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.