agentleFS
LeonxLJXLeonxLJX/web-engineer-skills/skills/api-contract-design/SKILL.md

api-contract-design

Skill0 starsChanged 2 months agoMITView on GitHub

Design frontend-backend contracts that age well — resource modeling, pagination, error envelopes, idempotency, versioning — for REST or tRPC. Use when adding endpoints, integrating an API, or fixing client-server misunderstandings.

6 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use testing-strategy.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • BlockSkill

    testing-strategy

    Guidelines for writing effective tests in this project

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 2

    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
  1. Very specific:

    Default to cursor pagination: ?cursor=<opaque>&limit=50, response carries nextCursor.

    line 21
  2. Distinctive:

    Every list response states its shape explicitly:

    line 22
  3. Distinctive:

    Every endpoint states its auth requirement in the schema.

    line 57

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API contract design (frontend ↔ backend)

Contract first

The schema (OpenAPI/GraphQL/tRPC types) is the source of truth, generated into the client. Hand-typed interfaces that "roughly match" the API rot within weeks.

Resource modeling

  • Nouns not verbs: POST /orders, not POST /createOrder.
  • Relationships in paths: GET /users/:id/orders?status=paid.
  • One resource, one shape. If the mobile app needs less, that's field selection/projection — not a second endpoint with mystery fields.

Pagination: offset is a trap

  • Offset (page=3) breaks under inserts/deletes and degrades on deep pages.
  • Default to cursor pagination: ?cursor=<opaque>&limit=50, response carries nextCursor. Opaque cursors also prevent clients from hand-crafting queries.
  • Every list response states its shape explicitly:
{ "items": [...], "nextCursor": "eyJpZCI6...", "hasMore": true }

Errors: one envelope, machine-readable

{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "email is not a valid address",
    "details": [{ "field": "email", "rule": "format" }],
    "requestId": "req_9f2c"
  }
}
  • HTTP status classes stay correct (4xx client, 5xx server) but the code string is what clients branch on — never parse message.
  • requestId on every error; it's the join key to server logs when a user reports "it didn't work".

Idempotency & retries

  • Non-GET from clients that retry (network flake, double-click) carries Idempotency-Key: <uuid>; server dedupes.
  • Client retries: exponential backoff + jitter, only on idempotent requests or with a key; timeouts on everything.

Versioning

  • Version at the URL or header (/v1/), never at field names (nameV2).
  • Additive changes only within a version; breaking changes bump.
  • Deprecation is a process: announce → dual-write window → remove. Clients see a Deprecation/Sunset header before the break.

Auth & multi-tenancy

  • Every endpoint states its auth requirement in the schema; the client's generated types force the token flow.
  • Tenant scoping is server-side on every query — "my orders" means where userId = caller, enforced once in the data layer, not per endpoint.

Definition of done (agent checklist)

  • Schema is generated/consumed, not hand-mirrored
  • Lists: cursor pagination + explicit envelope
  • Errors: code + details + requestId, statuses correct
  • Mutations: idempotency keys where retries possible
  • Breaking changes versioned; deprecation headers wired

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.