rest-api-design
Skill1 starsChanged 2 months agoMITView on GitHub
Design an HTTP API that stays coherent after v1 - resource modelling, nouns over verbs, status codes as a contract, RFC 9457 problem details for every error, idempotency keys, ETag/If-Match conditional writes, PATCH vs PUT, content negotiation, and versioning. Use when the user says "design a REST API", "endpoints for X", "API contract", "which status code", "error response format", "idempotency", "optimistic locking", or is reviewing an existing API before a client is written against it.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- 27Aaron/skillstheir own version, first seen Nov 29, 2026
- martinholovsky/claude-skills-generatortheir own version, first seen Nov 29, 2026
- bsene/skillstheir own version, first seen Oct 25, 2026
- Meet-08/skillstheir own version, first seen Sep 27, 2026
- bm629/agent-skillstheir own version, first seen Aug 21, 2026
- anurag-azure/skillstheir own version, first seen Jun 27, 2026
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- martinholovsky/claude-skills-generator★ 48same name
- bsene/skills★ 7same name
- 27Aaron/skills★ 2same name
- bm629/agent-skills★ 2same name
- emvnuel/skills★ 2same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
- anurag-azure/skills★ 0same name
- dhriyatinandu-bot/claude-skills★ 0same name
- dkprog/claude-skills★ 0same name
- Meet-08/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository126 other files it gives its agents.
- eu-data-backend-job-hunterSkill
- job-application-matcherSkill
- llm-agents-and-tool-useSkill
- llm-application-architectureSkill
- llm-cost-and-latency-optimizationSkill
- llm-evaluationSkill
- llm-fine-tuning-and-adaptersSkill
- llm-privacy-and-safetySkill
- llm-prompt-engineeringSkill
- llm-rag-systemsSkill
- structured-output-and-jsonSkill
- graphql-api-designSkill
- pagination-and-filteringSkill
- webhooks-and-integrationsSkill
- caching-architecture-multi-layerSkill
- resilience-patternsSkill
- service-boundaries-and-monolithsSkill
- system-design-interviewSkill
- go-concurrencySkill
- go-error-handlingSkill
- java-spring-patternsSkill
- nodejs-server-performanceSkill
- python-async-patternsSkill
- python-data-modelingSkill
- python-packaging-and-toolingSkill
- python-performanceSkill
- rest-api-implementationSkill
- rust-error-handlingSkill
- rust-ownership-patternsSkill
- typescript-type-safetySkill
- ci-caching-and-speedupSkill
- ci-pipeline-designSkill
- deployment-strategiesSkill
- github-actions-hardeningSkill
- release-versioning-and-changelogsSkill
- reproducible-buildsSkill
- aws-iam-and-securitySkill
- aws-serverless-architectureSkill
- azure-fundamentalsSkill
- cloud-cost-optimizationSkill
- cloud-networking-and-vpcSkill
- gcp-cloud-architectureSkill
- code-review-skillsSkill
- design-review-and-refactoring-architectureSkill
- refactoring-techniqueSkill
- understanding-unknown-codebaseSkill
- buildkit-and-cacheSkill
- container-image-debuggingSkill
- container-runtime-securitySkill
- docker-compose-workflowsSkill
- dockerfile-authoringSkill
- docker-image-optimizationSkill
- database-connection-managementSkill
- database-transactionsSkill
- distributed-databasesSkill
- nosql-data-modelingSkill
- postgres-query-tuningSkill
- redis-and-cachingSkill
- schema-migrationsSkill
- data-modeling-for-analyticsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
12 rules. 0 are common, 3 are distinctive, and 9 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
Prefer modelling the state change as a new resource or a field over an action endpoint.
- Very specific: line 42
Use an action endpoint only when the action is not a state transition of the resource: things that genuinely start something (POST /reports …
- Very specific: line 61
Never expose sequential database ids.
- Very specific: line 82
DELETE: should be idempotent: deleting an already-deleted resource returns 204 again, not 404. - Very specific: line 103
Read references/status-codes.md when the situation is not in that table — it has the full decision procedure and the traps (400 vs 422 vs …
- Very specific: line 109
Use RFC 9457 problem details (application/problem+json).
- Very specific: line 237
Negotiate on need, not on decoration: If you ship JSON only, say so in Content-Type and support Accept-Charset: utf-8 implicitly.
- Very specific: line 241
Always honour Content-Type on writes and return 415 for an unsupported one.
- Very specific: line 247
Versioning: Default: do not version until you have to.
- Distinctive: line 252
When you must break things, prefer, in order:
- Distinctive: line 273
When asked to design an API, emit this, in this order:
- Distinctive: line 335
When reviewing an existing API, report the exact fields whose semantics would change for existing clients.
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
REST API Design
Produce an endpoint table, a status-code contract, and one error shape that is identical across every endpoint. The goal is an API a client can write against from the documentation alone and that you can still change in year two.
Workflow
- 1. Model resources before endpoints (nouns, hierarchy, identifiers)
- 2. Pick one identifier style and stick to it
- 3. Decide
PUTvsPOSTvsPATCHper mutation, and what409means - 4. Choose the error shape once and apply it everywhere
- 5. Add
ETag/If-Matchfor any resource two clients may write - 6. Add
Idempotency-Keyto everyPOSTthat charges, sends, or creates - 7. Write the endpoint table, then review it against the Gotchas list
Step 1 — Resources, not endpoints
A resource is a thing with an identity. The test: can two URLs point at the same state? If yes, you have two resources; if no, you have a verb.
POST /orders -> creates Order (Order has its own id)
GET /orders/{id} -> reads it
POST /orders/{id}/cancel-> this is a verb, and it usually should not existPrefer modelling the state change as a new resource or a field over an
action endpoint. PATCH /orders/{id} with {"status": "cancelled"} is one
code path; POST /orders/{id}/cancel, POST /orders/{id}/archive, and
POST /orders/{id}/refund are three, each with its own auth, its own error
cases, and its own deprecation path.
Use an action endpoint only when the action is not a state transition of the
resource: things that genuinely start something (POST /reports — a report
takes minutes and has its own lifecycle) or are not idempotent by nature.
Nesting is for containment, not for hierarchy theatre. /orders/{id}/items is
good because an item does not exist outside an order. /orders/{id}/customer/
address/country is not. Cap nesting at two levels and let the leaf carry a
globally unique id.
Step 2 — Identifiers
Pick one and never mix:
| Style | Example | Notes |
| Opaque server id | GET /orders/01J8Z... | Default. No structure to leak, no guessable sequential ids |
| Natural key | GET /orders/2026-00041 | Only if it is a real business key you guarantee stable |
| Prefixed route | GET /orders/ord_01J8Z... | Useful when several resource types share an id space |
Never expose sequential database ids. They leak volume and they let a client
enumerate your customers by walking /orders/1, /orders/2, ….
Timestamps: created_at in RFC 3339 UTC with a Z suffix. Money: integer
minor units plus an ISO 4217 currency, never a float. {"amount": 1999,
"currency": "USD"}, not {"amount": 19.99}.
Step 3 — Methods and status codes
POST creates. Return 201 Created, a Location header pointing at the
new resource, and the resource body. If the client supplied an id, echo it; if
you generated one, put it in the body too.
PUT replaces. The full representation. Absent fields are cleared, not
preserved. PUT on a non-existent resource creates it. PUT must be
idempotent by definition: calling it twice leaves the same state. If your
"update" is not idempotent, it is a POST.
PATCH changes some fields. The default for user-driven updates, because
it avoids the "did I forget to send the unchanged field" class of bug.
DELETE should be idempotent: deleting an already-deleted resource returns
204 again, not 404.
| Situation | Status | Notes |
| Read succeeded | 200 | |
| Created | 201 | + Location |
| Accepted for later processing | 202 | + a status resource you can poll; no Location to the result |
| Successful mutation, no body | 204 | No body, and no Content-Type |
| Malformed JSON / bad params | 400 | Machine-parseable detail |
| Not authenticated / not authorized | 401 / 403 | Never 403 for "you are not logged in" |
| Not found | 404 | Also used to hide existence from unauthorized callers |
| Version conflict | 409 | Uniqueness, state-machine violation, or a failed If-Match |
| Precondition required | 428 | If you require If-Match and it is missing |
| Precondition failed | 412 | If-Match / If-None-Match did not hold |
| Payload too large | 413 | |
| Unsupported media type | 415 | |
| Rate limited | 429 | Must carry Retry-After |
| Server error | 500 | Never leak internals in the body |
| Dependency down | 503 | + Retry-After when you know the delay |
Read references/status-codes.md when the situation is not in that table —
it has the full decision procedure and the traps (400 vs 422 vs 409,
401 vs 403, 404 vs 403 for privacy).
Step 4 — The error shape (emit this)
Use RFC 9457 problem details (application/problem+json). One shape, all
endpoints, forever. The agent should emit this template and fill it in:
{
"type": "https://api.example.com/problems/insufficient-funds",
"title": "Insufficient funds",
"status": 409,
"detail": "The wallet balance of 400 USD is less than the 1250 USD required.",
"instance": "/v1/transfers/7f3a/transfers",
"trace_id": "0af7651916cd43dd8448eb211c80319c",
"errors": [
{ "field": "amount", "code": "amount_too_large",
"message": "Must not exceed the available balance." }
]
}Field rules:
typeis a stable URI you control. Clients branch on this or oncode, never ondetailortitleprose.titleis a short human summary, same value for the sametypeevery time.detailis for this one occurrence, and must never contain a stack trace, SQL fragment, internal hostname, or stack frame.instanceis the request path.trace_idis the correlation id you also put in your logs — without it, a user-reported failure is unactionable.errorsis your extension: a list of machine-readable field errors for validation failures,[]or absent otherwise. Put your extensions at the top level, not under a namespace, and never add them conditionally to the standard fields.
Fastly's application/problem+json is the de-facto shape; it is what RFC 9457
standardised. Send Content-Type: application/problem+json for all of it,
including 400 and 500 — not application/json.
Validation errors
One request, many problems: report all of them, and do not partially apply. Validate the whole body, then write.
{
"type": "https://api.example.com/problems/validation-failed",
"title": "Validation failed",
"status": 422,
"detail": "The request body has 2 invalid fields.",
"errors": [
{ "field": "email", "code": "invalid_format", "message": "Must be a valid email address." },
{ "field": "quantity", "code": "out_of_range", "message": "Must be between 1 and 100." }
]
}Step 5 — Conditional writes (ETag / If-Match)
Any resource that two clients might edit concurrently gets an ETag. It is
one header on read and one check on write, and it eliminates a whole class of
lost updates.
GET /v1/orders/42
→ 200
ETag: "v7-9f2c1a"
Last-Modified: Tue, 03 Mar 2026 10:15:00 GMTPATCH /v1/orders/42
If-Match: "v7-9f2c1a"
Content-Type: application/json
{ "status": "shipped" }
→ 412 Precondition Failed (someone else wrote first)
→ 200 with the new ETag (you won)Implementation, using a row version column:
ETag: "v<version>-<hash of updated_at>"— or just"7". It only has to change when the representation changes.If-Match: *means "only if it exists". Use it to make a create-or-replacePUTsafe.- If the
If-Matchvalue does not match, fail the whole write with412— do not silently retry the update on top of the new version. A silent retry is a lost update wearing a disguise. - Clients must read the new
ETagfrom your response. A client that reuses a staleETagforever will get412on every write — that is a client bug, and yourdetailmessage should say "resource changed; re-read and re-apply". If-None-Match: *onGETmeans "304 Not Modified if it exists" — the cheap way to implement a cache revalidation.
Step 6 — Idempotency keys
PUT and DELETE are idempotent by the spec. POST is not, and retries on
unreachable-but-processed POSTs are the single most common source of
duplicate charges and duplicate rows. Fix it with a client-supplied key.
POST /v1/payments
Idempotency-Key: 8f14e45f-ceea-467a-9c2a-6b3f1c9d0e77
Content-Type: application/json
{ "amount": 1250, "currency": "USD", "order_id": "01J8Z..." }Server rules:
- Scope the key to the authenticated principal. Two tenants must never share a key namespace.
- Store
(principal, key) -> (request_fingerprint, status_code, response_body, created_at)and set a TTL. 24 hours is a sane default; match it to your retry window, not to your data retention. - Replay the stored response for a repeat key, including the original status
code. Return
409if the same key arrives with a different body — that is a client bug and silently returning the old result hides it. - Insert the key in the same transaction as the effect. If you write the key first and the transaction later fails, a legitimate retry is now permanently rejected.
- Return the key back in a response header so a client debugging a duplicate can find it.
Key format: a UUIDv4 or a high-entropy random string. Idempotency-Key:
<order_id> is not a key, it is a collision waiting for a retry after a
partial failure.
Step 7 — Content negotiation and versioning
Negotiate on need, not on decoration. If you ship JSON only, say so in
Content-Type and support Accept-Charset: utf-8 implicitly. Add negotiation
for Accept (JSON vs XML) and Accept-Language only when a client actually
needs it, and return 406 Not Acceptable when you cannot satisfy Accept.
Always honour Content-Type on writes and return 415 for an unsupported one.
Pagination parameters (limit, cursor, sort) belong in the query string;
they are not a second content type. See
skills/api-design/pagination-and-filtering/SKILL.md for the cursor design.
Versioning. Default: do not version until you have to. A field a client
ignores is not a breaking change. Break a client only by removing or renaming a
field, changing a type, tightening validation, or changing a status code or
error code.
When you must break things, prefer, in order:
- Additive change — new optional field, new endpoint. Free.
- Parallel running — new field alongside the old one, deprecated in docs, sunset on a stated date.
- Media-type versioning — pin the version to the URL path
(
/v1/..., the pragmatic default) or to a custom media type parameter (Accept: application/vnd.example.order+json; version=2). Path versioning is what most clients, proxies, and humans handle well; media types are cleaner but you must acceptAcceptheaders on every single request and many gateways drop the parameter. - A new major domain —
api.example.com/v2when the shape changed too much to carry.
Whatever you pick: publish a machine-readable changelog and a per-version
sunset date, and answer Deprecation: true and Sunset: <HTTP-date>
headers on the deprecated version (RFC 8594). A deprecation nobody can
discover is not a deprecation.
Output template
When asked to design an API, emit this, in this order:
## Resources
| Resource | Identifier | Notes |
## Endpoints
| Method | Path | Success | Auth | Idempotent | Errors |
|---|---|---|---|---|---|
## Error contract
(RFC 9457 example, Content-Type, and the field semantics)
## Concurrency
Which resources carry ETag, and what If-Match does on each write path.
## Idempotency
Which POST endpoints require Idempotency-Key, the TTL, and the fingerprint rule.
## Versioning policy
What counts as breaking here, and the deprecation mechanism.Gotchas
400is for malformed syntax,422is for well-formed but semantically invalid,409is for a conflict with current state. Most teams pick one and then clients cannot tell a retryable failure from a permanent one. Pick all three and use them.- Never return
200with{"success": false}. Status code and body must agree. Clients (and every proxy, retry policy, and monitoring dashboard) branch on the status. 403leaks existence.GET /orders/{someone_elses_id}returning403confirms the order exists. Return404unless the caller has a legitimate need to know.- A
500with a stack trace in the body is a vulnerability, not a debugging aid. Log the trace with thetrace_id; return thetrace_id. Locationon a201should be fetchable with the same credentials. If creation returns a resource the client then cannotGET, you have built two auth paths.- Field-level
PATCHwithnullis ambiguous. Decide and document: JSON Merge Patch (application/merge-patch+json, RFC 7396) meansnullclears the field andnullis not a value; JSON Patch (application/json-patch+json, RFC 6902) is an operation list and is exact but verbose. Pick one per endpoint and set theContent-Typeto say which. If you accept plainapplication/jsonforPATCH, you have silently chosen "null means null" and your clients cannot clear a field. - Bulk endpoints are not free.
POST /orders/bulkneeds a per-item result array, a partial-failure mode, and its own idempotency story. Prefer aGETplus per-itemPOSTs under a queue until the volume justifies it. - Long operations return
202plus a status resource, not a200with{"status": "processing"}that the client has to poll with an undocumented interval. - Delete-vs-GDPR: a hard delete must be documented as
asynchronous, and a "deleted" tombstone that 404s on
GETis a common and much cheaper approach than deleting rows a foreign key still points at.
Safety notes
- Additive changes only. Do not remove or rename a published field, change a type, or tighten validation on an existing endpoint without an explicit version bump and a written migration note for clients.
- When reviewing an existing API, report the exact fields whose semantics would change for existing clients. Do not silently "clean up" a published contract.
Idempotency-Keystorage is a write to your database. Say so before adding it to a hot endpoint, and give the TTL.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

