awesome-everything RU
↑ Back to the climb

APIs

APIs: contract and response reading

Crux Read real API contracts, responses, a pagination query, and rate-limit headers, then pick the senior call — the highest-leverage fix or the correct interpretation.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

API problems are diagnosed in the contract and on the wire: a route table, a response, a SQL page query, a set of response headers. Read each one and choose the call a senior would make first.

Goal

Practise the review loop you run on every public API: read the contract or the response, predict where it breaks under load or retry, and reach for the structural fix before reaching for a workaround.

Snippet 1 — the route table

POST   /chargeCard
POST   /refundCharge?id=123
GET    /getUserOrders?user=42
POST   /orders/{id}/cancel?action=cancel
Quiz

This route table mixes several modeling mistakes. What is the single highest-leverage correction, and why does it matter most?

Snippet 2 — the create-payment response

POST /payments
Idempotency-Key: 8f1c-...-a9
--> HTTP/1.1 200 OK
    { "status": "ok", "error": null }
Quiz

The client sent an Idempotency-Key and the server returned 200 with no resource id. A timeout-driven retry follows. What is wrong and what should the server return?

Snippet 3 — the deep-page query

-- page 5001 of a live, growing feed
SELECT id, created_at, title
FROM posts
ORDER BY created_at DESC
OFFSET 100000 LIMIT 20;
Quiz

This query backs a live, growing feed and deep pages are slow and occasionally drop or duplicate posts. What is the cursor-based rewrite and what does it buy?

Snippet 4 — the rate-limit headers

HTTP/1.1 429 Too Many Requests
Retry-After: 8
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1716998400
Quiz

A client got this response. What is the correct client behavior, and what does each signal mean?

Recap

Every API review reads the same artifacts: a route table tells you whether resources are nouns (and therefore whether status codes can be honest); a create response should be 201 + Location on first write and 200 on an idempotent replay, never a bare 200 with no id; a deep-page query should be a keyset cursor on a unique composite sort key, not OFFSET; and a 429 with Retry-After + X-RateLimit-* is a cooperative backoff contract the client must honor. Read the contract, predict the failure under retry or load, then apply the structural fix.

Continue the climb ↑APIs: design and build a production API
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.