api-contract-design
Skill4 starsChanged 4 months agoMITView on GitHub
Designing HTTP/REST APIs, request/response shapes, error formats, versioning, pagination, idempotency, and webhooks. Use when adding or changing endpoints, integrating a frontend with a backend, designing public or partner APIs, or when the user says "API design", "endpoint", "REST", "contract", "breaking change", or "webhook".
6 other projects use a version of this.
Adopted by
Most recently taken up by
- OugeX/dsh-web-dev-modetheir own version, first seen Nov 1, 2026
- chadixearth/graphylooptheir own version, first seen Oct 13, 2026
- dathuynh1108/agent-skillstheir own version, first seen Oct 11, 2026
- hemapriyan-rk/claude-rigor-skillstheir own version, first seen Sep 26, 2026
- LeonxLJX/web-engineer-skillstheir own version, first seen Sep 3, 2026
- MohOneX/claude-opus-skillstheir own version, first seen Jun 6, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- dathuynh1108/agent-skills★ 4same name
- chadixearth/graphyloop★ 3same name
- hemapriyan-rk/claude-rigor-skills★ 1same name
- LeonxLJX/web-engineer-skills★ 0same name
- MohOneX/claude-opus-skills★ 0same name
- OugeX/dsh-web-dev-mode★ 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 repository23 other files it gives its agents.
- ai-agent-designSkill
- ai-build-qualitySkill
- ai-engineeringSkill
- architecture-designSkill
- change-hygieneSkill
- code-qualitySkill
- database-designSkill
- data-privacy-complianceSkill
- dependency-disciplineSkill
- deployment-safetySkill
- docs-and-runbooksSkill
- legacy-code-changesSkill
- observability-readinessSkill
- payments-and-moneySkill
- performance-improvementSkill
- product-ux-qualitySkill
- release-readinessSkill
- requirements-to-specSkill
- root-cause-debuggingSkill
- saas-multi-tenancySkill
- system-designSkill
- testing-strategySkill
- threat-model-securitySkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
When you must break: new field alongside old → dual-write/dual-read → migrate clients → deprecate with a date → remove.
“Common” is measured: kept by at least 6 in 10 of the 4 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
API Contract Design
An API is a promise. Clients — your own frontend, partners, and AI models writing integrations — build on exactly what you return, including your mistakes. Design every endpoint as if you can never change it, because for practical purposes you can't (only add).
Contract-first, always
Before writing the handler, write the contract: method, path, auth, request shape, response shape, every error case with its code. Five minutes of contract prevents the frontend and backend from building two different APIs. Keep it wherever it's enforceable — OpenAPI, typed schemas (Pydantic/zod), or at minimum a markdown table — the schema layer IS the documentation if you make it one.
Shape rules
- Resources and predictability over cleverness: plural nouns (
/invoices/{id}), nesting only one level deep when ownership is intrinsic (/invoices/{id}/payments); verbs only for true actions (/invoices/{id}/cancel). A developer should guess the next endpoint correctly. - Response envelopes are uniform across the whole API: pick one success shape and ONE error shape (
{"error": {"code", "message"}}-style) and never deviate. Machine-readablecode(stable, documented, for programs) + humanmessage(for humans, changeable). Clients that parse message strings are a bug you caused. - Every list endpoint, from day one: pagination (limit + cursor/offset), a deterministic default sort, and filters as query params. Retrofitting pagination onto a client that assumes "all rows" is a breaking change.
- Field conventions fixed project-wide: one case style, ISO-8601 timestamps in UTC, money as string-decimal or integer minor units (never JSON floats), booleans not 0/1 strings,
nullvs absent given meaning consistently. - Return the resource state after mutation (the created/updated object), so clients don't need a follow-up GET.
Status codes — the short honest set
200 read/update ok · 201 created · 204 deleted/no body · 400 malformed/validation · 401 who are you · 403 you can't do that (but see threat-model-security: prefer 404 when existence itself is private) · 404 not found or hidden · 409 state conflict (duplicate, already-cancelled) · 422 semantic validation if you distinguish it · 429 rate limited · 5xx our fault, never leaks internals. Don't return 200 {"success": false} — that lies to every HTTP-aware layer between you and the client.
Idempotency — the rule everyone skips until it costs money
- GET/PUT/DELETE are naturally idempotent; keep them so.
- Any POST that creates something valuable or moves money accepts an idempotency key (client-generated, stored unique): the retry after a timeout must not create a second payment. Networks fail after the server succeeds; without this, your client's only options are "maybe duplicate" or "maybe lose it".
- Everything a queue/webhook/cron touches follows the same rule (see system-design).
Evolution without breakage
Safe: adding optional request fields, adding response fields, adding endpoints/enum-values clients were told to tolerate. Breaking: removing/renaming fields, type changes, semantics changes, tightening validation, changing defaults, changing error codes.
- Clients must ignore unknown response fields (say this in the contract); servers must reject unknown fields only where security demands it.
- When you must break: new field alongside old → dual-write/dual-read → migrate clients → deprecate with a date → remove. Version (
/v2) only when the surface change is too broad for field-level evolution. - Your own frontend counts as a client: deploys aren't atomic across app and API; the old frontend will talk to the new API for a while (and cached bundles make "a while" longer than you think).
Webhooks you emit
Sign payloads (HMAC + timestamp), retry with backoff on non-2xx, provide a redelivery/reconciliation path, and document that consumers must be idempotent. Send a thin event (type, id, minimal data) and let consumers fetch fresh state — fat payloads go stale in retry queues.
Review checklist
- Can every error the handler can produce be triggered deliberately, and does each map to the documented envelope + code?
- Does any endpoint return different shapes for the same status? (Fix it.)
- Walk a slow-network retry through every POST: what duplicates?
- Diff against the previous contract: is every change in the "safe" list? If not, where's the migration plan?
- Auth on every route confirmed server-side — including the "internal" ones that are one leaked URL away from public (threat-model-security Gate 2).
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.

