Part I — The Pipes · Lesson 1.5
REST APIs
In one lineNouns as URLs, verbs as methods, state in the response — and every call stands alone.
Where you've seen itGET /2/tweets/:id on the Twitter API. Same URL, same result, cacheable by every layer in between.
Diagram
STATUS CODES THE CLIENT MUST BRANCH ON
2xx 200 ok 201 created 204 no content
3xx 304 not modified ← ETag hit, body not re-sent
4xx 400 bad input 401 not logged in 403 logged in, not allowed
404 missing 409 conflict 429 rate limited → back off
5xx 500 server bug 503 down → retry with backoffHow it works
- Model resources, not procedures.
/orders/9/itemsbeats/fetchOrderItems. - Pick the verb by semantics, then let infrastructure act on it — proxies cache
GET, clients safely retryPUT. - Return the state, plus a
Locationheader on201. - Version at the edge —
/v1/...or anAcceptheader — and never break a live contract. - Paginate with cursors for feeds, offsets for stable tables.
Trade-offs
| Use REST when | Reach for something else when |
|---|---|
| Resources map cleanly to entities | One screen needs 6 nested resources → GraphQL |
| You want HTTP caching for free | Payloads are huge and internal → gRPC |
| Many unknown third-party clients | Client needs field-level control |
The classic pain: a profile screen firing /user, /user/posts, /user/followers, /user/settings — four round trips before first paint. This is exactly the gap the next lesson fills.
Interview angle
"PUT or PATCH — and why does it matter for retries?"
PUTreplaces the whole resource and is idempotent, so a timeout can be retried safely.PATCHapplies a delta and generally isn't, so retries need an idempotency key.- On flaky mobile networks, retry safety is a design decision, not a detail.
Recap
- URLs are nouns; methods are the verbs.
- Idempotency decides whether a client may retry.
- Free HTTP caching is REST's biggest advantage — and over-fetching is its biggest cost.