HTTP API design: methods, status codes, pagination, and errors
Many APIs called REST are really RPC over HTTP. This quiz covers the choices that matter once other developers build against your endpoints: safe and idempotent methods, PUT vs. PATCH vs. POST, idempotency keys, cursor vs. offset pagination, what 409, 412, 422, and 429 mean, versioning, and error formats a client can parse. Most answers point to the relevant spec (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. You want to change a user's
emailand leave every other field alone. Which method fits best? - Not answered. Why is
PATCHnot guaranteed to be idempotent, whilePUTis? - Not answered. A
POST /chargesrequest times out before the response arrives, and the client retries. How do you prevent a double charge? - Not answered. An infinite-scroll feed reads from a table that keeps growing. Users must never see a duplicate or miss an item, and page 10,000 must load as fast as page 1. Which pagination design fits?
- Not answered. Which of these are real drawbacks of
OFFSET/LIMITpagination that keyset pagination avoids? - Not answered. Your API handles optimistic concurrency with a
versionfield in the request body. A client sendsversion: 3, but the stored resource is already atversion: 5because someone else updated it first. The request has noIf-Matchheader. Which status code fits? - Not answered. A client sends a conditional update with
If-Match: "v5"to avoid lost updates, but the resource's currentETagis"v7". Per RFC 9110, which 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. Which status code is most precise? - Not answered. A client goes over its rate limit. Which status code should the server return, and which header tells the client when to try again?
- Not answered. Which response change is backward compatible, so you can ship it to existing clients without a new API version?
- Not answered. Per RFC 9457 (Problem Details for HTTP APIs), what media type goes in the
Content-Typeheader of a JSON error document? - Not answered. An API returns HTTP
200for everything and signals failure with{ "ok": false }in the body. What's the main problem?