Designing an HTTP API (REST, Done Right)
Most "REST" APIs are RPC in disguise. This quiz sharpens the decisions that matter when other people build against your endpoints: method safety and idempotency, PUT/PATCH/POST, idempotency keys, cursor vs. offset pagination, the real meaning of 409/412/422/429, versioning, and error envelopes a client can program against. Every answer is grounded in the HTTP specs (RFC 9110, RFC 5789, RFC 9457).
Questions
- Not answered. Which of these HTTP methods are idempotent?
- Not answered. What does it mean for an HTTP method to be "safe"?
- Not answered. Update only a user's
email, leaving every other field untouched. Which method fits best? - Not answered. Why is
PATCHnot guaranteed to be idempotent, whilePUTis? - Not answered. A
POST /chargestimes out before the response arrives; the client retries. How do you prevent a double charge? - Not answered. An infinite-scroll feed over a constantly-growing table: a user must never see a duplicate or skip an item, and page 10,000 must be as fast as page 1. Which pagination design fits?
- Not answered. Which of these are genuine drawbacks of
OFFSET/LIMITpagination that keyset pagination avoids? - Not answered. Your API does optimistic concurrency with a
versionfield in the request body. A client sendsversion: 3, but the stored resource is already atversion: 5— someone updated it first. NoIf-Matchheader was sent. Which status code? - Not answered. A client does a conditional update with
If-Match: "v5"to avoid lost updates, but the resource's currentETagis"v7". Per RFC 9110, what 3-digit status code must the server return? - Not answered. A client
POSTs well-formed JSON to create a user, butemailis"not-an-email"and fails validation. The body parsed fine. Which status code is most precise? - Not answered. A client exceeds its rate limit. What's the correct status code, and which header should tell it when to try again?
- Not answered. Which response change is backward-compatible — safe to ship to existing clients without cutting a new API version?
- Not answered. Per RFC 9457 (Problem Details for HTTP APIs), what media type does a server put on
Content-Typefor a JSON error document? - Not answered. An API returns HTTP
200for everything and signals failure with{ "ok": false }in the body. What's the core problem?