REST API Design Cheat Sheet: Methods, Status Codes and Idempotency
Checked against HTTP (RFC 9110) RFC 9110 (HTTP Semantics), RFC 5789 (PATCH), draft-ietf-httpapi-idempotency-key-header-09 on 28 November 2026. Each section links to the official docs it was checked against.
This is for backend developers designing JSON-over-HTTP APIs who want answers grounded in the HTTP specs rather than in blog folklore. The method and status code rows come from RFC 9110 and RFC 5789. Anything the RFCs don't define, such as pagination parameters or URL versioning, is labelled as a convention.
When to use what
Choose the method by what the request promises, not by what the handler does. GET, HEAD, OPTIONS and TRACE are safe: the client asks for no state change. PUT and DELETE are idempotent as well, which means a client or proxy may resend them after a timeout without asking you. POST and PATCH carry neither promise, so a retried POST can create two orders. That is the gap idempotency keys fill.
Use PUT when the client sends the whole resource and PATCH when it sends a set of changes. If your PUT handler quietly keeps fields the client left out, you have built a PATCH with the wrong name, and clients will rely on it.
For errors, the honest test is "what can the client do next?" 400 says fix the request, 401 says authenticate (and you must send WWW-Authenticate), 403 says don't bother retrying with the same credentials, 409 says the current state blocks this, and 422 says the syntax was fine but the content wasn't. Our HTTP status codes tool and method reference are quick lookups, and the status codes guide goes deeper. For versioning there is no standard; the API versioning post compares the options.
Safe means the client doesn't request a state change. Idempotent means sending the same request several times has the same intended effect as sending it once. Both are promises about intent; your server can still log or count requests.
GETRead a representation; safe and idempotent, so caches and crawlers may call it freely
HEADSame as GET without the body; safe and idempotent, handy for checking size or ETag
OPTIONSAsk which methods and features a resource supports; safe and idempotent
POSTProcess the enclosed content, often to create a subresource; neither safe nor idempotent
PUTCreate or replace the resource at this URL with the enclosed state; idempotent, not safe
DELETERemove the mapping for this URL; idempotent, not safe
PATCHApply a set of changes described in the body; neither safe nor idempotent (RFC 5789)
POST -> 201 Created + LocationReturn 201 with a Location header naming the new resource when POST creates one
PUT -> 201 or 200/204Return 201 if PUT created the resource and 200 or 204 if it replaced an existing one
DELETE -> 202 / 204 / 200202 if deletion is queued, 204 if done with nothing to say, 200 if done and you return a status body
405 + AllowReject an unsupported method; RFC 9110 requires an Allow header listing the methods you do support
401 + WWW-AuthenticateSignal missing or invalid credentials; the challenge header is mandatory
409 ConflictRefuse because the resource's current state conflicts, such as an edit on a stale version
412 Precondition FailedReject a conditional request whose If-Match or similar header evaluated to false
422 Unprocessable ContentReject well-formed content that fails validation or business rules
A PATCH must apply all changes or none. Advertise accepted patch formats with Accept-Patch.
PUT /users/42 {full body}Replace the whole resource; fields you omit are expected to be reset, not kept
PATCH /users/42 + Content-Type: <patch format>Send a description of the changes in a declared patch media type, not a full resource
If-Match: "e0023aa4e"Make a PATCH or PUT conditional on the ETag so two clients can't overwrite each other
415 + Accept-PatchReject a patch format you don't support and list the formats you do
422 on PATCHReject a patch that is valid but would leave the resource in an invalid state
Draft, not a standard: draft-ietf-httpapi-idempotency-key-header-09. Expiry is left to each API, which should document it. See our idempotency keys post.
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"Mark a POST or PATCH so the server can return the first result for retries; the value is a quoted structured-field string
400 when the key is missingTell the client this endpoint requires a key, ideally with a problem-details body linking your docs
422 when a key is reused with a different bodyRefuse a retry that isn't really a retry
409 while the first request is still runningAsk the client to retry later without changing anything
None of these are defined by an RFC. They are common conventions; pick one and use it everywhere in your API.
GET /notes?limit=50&cursor=abcCursor pagination (convention); stable when rows are inserted while a client pages
GET /notes?page=3&per_page=50Offset pagination (convention); easy to jump to a page, but rows shift under concurrent writes
GET /notes?status=open&sort=-created_atFilter and sort with query parameters (convention); document the allowed fields
/v1/notesVersion in the path (convention); visible and cache-friendly, but every version is a new URL
Accept: application/vnd.example.v2+jsonVersion by media type (convention); keeps URLs stable but is harder to try in a browser
Worked example: Make a payment endpoint safe to retry
A mobile client posts a payment, the network drops, and the app retries. Without a key, that's two charges. With one, the flow looks like this:
POST /payments HTTP/1.1
Content-Type: application/json
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"
{"amount": 1200, "currency": "eur"}
HTTP/1.1 201 Created
Location: /payments/pay_81
The server stores the key with the request fingerprint and the response. When the identical retry arrives, it returns the stored 201 and the same Location instead of charging again. If the retry arrives while the first request is still running, the draft says to answer 409, which tells the client to wait and try again unchanged. If a buggy client reuses the key with a different amount, the server answers 422, because that's a new request wearing an old key. Notice what didn't need a key: a PUT /payments/pay_81/note that sets a note is already idempotent under RFC 9110, so resending it is harmless. Keys earn their place on POST and PATCH, which carry no such promise. Write down how long you keep keys; the draft leaves that to you.
Common mistakes
Using GET for actions like
/users/42/deletebecause it is easy to call from a link.Crawlers, prefetchers and caches assume GET is safe. Use DELETE or POST so a link preview can't delete data.
Returning 200 with
{"error": ...}in the body for failures.Use a 4xx or 5xx code so clients, proxies and monitoring see the failure; put details in the body as well.
Sending 401 without a
WWW-Authenticateheader, or using 401 when the user is known but lacks rights.Send the challenge header with every 401, and use 403 for an authenticated caller who isn't allowed.
Retrying POST automatically in a client library because the request timed out.
Retry only idempotent methods automatically, or send an Idempotency-Key the server honours.
Answering 405 without listing what is allowed.
RFC 9110 requires an
Allowheader on 405, such asAllow: GET, HEAD.
Related cheat sheets
Sources
- https://www.rfc-editor.org/rfc/rfc9110.html
- https://www.rfc-editor.org/rfc/rfc5789.html
- https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.