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
RESOURCE TREE β URLs name things, not actions
/users
βββ /users/42 one user
β βββ /users/42/posts that user's posts
β βββ /users/42/followers
βββ /users?role=admin&page=2 filter + paginate via query
β /getUserById?id=42 β /users/42/delete β verbs in the URLVERB MATRIX
Method Purpose Safe Idempotent Cacheable Body
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
GET read β β β no
POST create β β β yes
PUT replace β β β yes
PATCH partial update β β β yes
DELETE remove β β β no
Safe = changes nothing
Idempotent = calling it 5 times == calling it once (retry-safe)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.