awesome-everything RU
↑ Back to the climb

APIs

REST modeling: request and design reading

Crux Read real HTTP requests, URL designs, and response shapes, predict the failure, and pick the highest-leverage fix a senior would make first.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

API design defects show up in the wire format — the request line, the URL shape, the response body. Read each snippet, find the trap, and choose the fix a senior engineer would make first.

Goal

Practise the loop you run in every API review: read the request and the resource shape, predict what breaks in production, and reach for the structural fix before patching symptoms.

Snippet 1 — the state-change request

PATCH /orders/42 HTTP/1.1
Content-Type: application/json

{ "status": "cancelled" }
Quiz

This is how the API cancels an order. What is the defect, and the fix?

Snippet 2 — the resource URL design

GET  /getUserOrders?userId=7
POST /createOrderForUser?userId=7
GET  /customers/7/projects/3/orders/42/items/9/discounts
Quiz

Two distinct modeling smells appear in these three lines. Name them and the redesign.

Snippet 3 — the idempotent retry

POST /payments HTTP/1.1
Idempotency-Key: 7f3c9a2e-...-d41
Content-Type: application/json

{ "amount": 4200, "currency": "usd", "source": "card_x" }
Quiz

The client sends this request, the TCP connection drops before the response arrives, and the client retries the identical request with the same Idempotency-Key. What must the server do?

Snippet 4 — the leaky response

{
  "id": 42,
  "full_name": "Ada Lovelace",
  "password_hash": "$2b$12$...",
  "is_deleted": false,
  "internal_risk_score": 0.13
}
Quiz

This is a user resource serialized straight from the ORM row. What is wrong, and the structural fix?

Recap

Every API defect reads off the wire: a writable status field is an unguarded transition (use a guarded action resource); verbs in the path and six-level nesting are RPC and chattiness (noun resources, shallow paths, IDs at the root); a retried POST needs an idempotency key to dedupe safely; and a row serialized straight to JSON leaks credentials and internal fields while welding the contract to your schema (map through a DTO). Read the request, find the structural smell, fix the shape — not the symptom.

Continue the climb ↑REST modeling: design an order API that survives change
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.