agentleFS
Lukk17Lukk17/agent-standards/.agents/skills/api-design/SKILL.md

api-design

Skill1 starsChanged 57 days agoMITView on GitHub

HTTP and GraphQL contract design covering resource naming, method and status-code semantics, RFC 7807 error bodies, pagination, idempotency, conditional requests, health endpoints, rate-limit headers and tiers, and versioning. Use when you say "design this endpoint", "what status code should this return", "review our API contract", "add cursor pagination to this list", or "how do we deprecate v1". Not for the service code behind the endpoint, use `backend-patterns`.

125 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use data-modeling, ci-pipeline and 7 more.

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.
  • mmondoraSkill

    data-modeling

    Schema design, multi-tenant data isolation, and migration management. Firestore and PostgreSQL patterns, RLS, UUID v7 conventions. Use when designing database schemas, writing migrations, or implementing multi-tenant data access.

    Also in 7 projects that use this

  • vndeeSkill

    ci-pipeline

    Use when creating or updating CI/CD pipelines with GitHub Actions or GitLab CI for Go, Python, or React projects

    Also in 4 projects that use this

  • pluginagentmarketplaceSkill

    microservices

    Microservices architecture patterns and best practices. Service decomposition, inter-service communication, and distributed data management.

    Also in 4 projects that use this

  • kevinaimonsterSkill

    typescript-strict

    TypeScript strict mode and advanced type system assistant. Helps write strictly-typed TypeScript code with generics, type guards, utility types, conditional types, mapped types, and template literal types. Trigger when user says 'TypeScript types' 'type gymnastics' 'TypeScript generics' 'strict TypeScript' 'type guard' 'TS类型' 'TypeScript严格模式' '类型体操' '泛型怎么写' 'TS type help'. Keywords: TypeScript, strict mode, generics, type guard, utility types, conditional types, mapped types, template literal types, infer, extends, keyof, typeof, type narrowing, discriminated unions, type assertion, type predicate, type gymnastics, TS, 类型体操, 泛型, 类型守卫, 严格类型

    Also in 4 projects that use this

  • DatabricksSkill

    load-testing

    Load test a Databricks App to find its maximum QPS. Use when: (1) User says 'load test', 'benchmark', 'QPS', 'throughput', or 'performance test', (2) User wants to find how many queries per second their app can handle, (3) User wants to set up load testing scripts for their agent, (4) User wants to view load test results/dashboard, (5) User wants to validate results or observe latency/error rate with MLflow tracing.

    Also in 4 projects that use this

  • CloudAI-XSkill

    database-design

    Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.

    Also in 15 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 104 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use kebab-case for multi-word resources, nest only to express ownership, and reserve a verb path segment for a genuine state transition …

    line 68
  2. Very specific:

    Every error body uses Content-Type: application/problem+json and the RFC 7807 shape, so one client-side handler covers every endpoint.

    line 115
  3. Very specific:

    Use POST /resources/batch for bulk work and report per-item outcomes, because one failed item must not discard the other ninety-nine.

    line 196
  4. Very specific:

    Put the version in the URL, keep at most two active versions, and give a deprecated one at least six months.

    line 269

“Common” is measured: kept by at least 6 in 10 of the 104 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 Design

Conventions for HTTP and GraphQL contracts that stay predictable as an API grows and gains external callers. The contract is the deliverable here, so everything is about what goes on the wire and nothing about the code that produces it.

Standards baseline, current as of September 2026: HTTP semantics per RFC 9110, problem responses per RFC 7807, descriptions written in OpenAPI 3.1, GraphQL over the graphql-ws transport.


When to activate

  • Designing a new endpoint or reviewing an existing API contract.
  • Choosing a status code, an error body, or a response envelope.
  • Adding pagination, filtering, or sorting to a collection endpoint.
  • Planning a versioning or deprecation path for a public or partner API.
  • Deciding what an endpoint must accept to be safe to retry.

When not to activate

  • Service structure, layering, or data access behind the endpoint: use backend-patterns.
  • Node, Express, or Next.js implementation of a handler: use node-backend-patterns.
  • Spring Boot controllers and their error handling: use springboot-patterns.
  • Authentication mechanics and token verification: use security-review. Threat modelling: use the security-auditor agent.
  • SOAP and WSDL contracts: use soap-webservices.
  • Writing the reference documentation for a finished contract: use markdown-writer.

Reference map

TaskOpen
Pagination, filtering, sorting, search, sparse fieldsetsreferences/pagination-and-filtering.md
Versioning strategy, deprecation, and sunset headersreferences/versioning.md
GraphQL schema, resolvers, and production hardeningreferences/graphql.md
A working handler in TypeScript, Python, or Goreferences/implementation-examples.md

Name resources as plural nouns

A URL identifies a thing. The method says what you are doing to it, so a verb in the path duplicates the method and splits one resource across several names.

# PASS
GET    /api/v1/team-members
GET    /api/v1/users/123/orders
POST   /api/v1/orders/456/cancel

# FAIL
GET    /api/v1/getUsers
GET    /api/v1/user
GET    /api/v1/team_members
GET    /api/v1/users/123/getOrders

Use kebab-case for multi-word resources, nest only to express ownership, and reserve a verb path segment for a genuine state transition that no method expresses, such as cancel or refund.


Use the method that matches the semantics

MethodIdempotentSafeUse for
GETYesYesRetrieving a resource
POSTNoNoCreating a resource, triggering an action
PUTYesNoReplacing a resource in full
PATCHNot inherentlyNoUpdating part of a resource
DELETEYesNoRemoving a resource

PATCH becomes idempotent when the body describes a target state rather than a delta. {"status": "shipped"} is idempotent, {"increment_views": 1} is not.


Return the status code that describes what happened

200 OK                     GET, PUT, PATCH with a response body
201 Created                POST, with a Location header pointing at the new resource
204 No Content             DELETE, or PUT with no body to return
207 Multi-Status           a bulk operation with per-item outcomes
304 Not Modified           a conditional GET whose resource is unchanged
400 Bad Request            malformed syntax, unparseable JSON
401 Unauthorized           missing or invalid credentials
403 Forbidden              authenticated, and still not allowed
404 Not Found              no such resource, or its existence is confidential
409 Conflict               duplicate, or a state that forbids this transition
422 Unprocessable Content  syntactically valid, semantically wrong
429 Too Many Requests      rate limit exceeded, with Retry-After
500 Internal Server Error  unexpected failure, never with internal detail
502 Bad Gateway            an upstream dependency failed
503 Service Unavailable    overloaded or draining, with Retry-After

Fail: HTTP 200 carrying {"status": 200, "success": false, "error": "Not found"}, which forces every client to parse the body before it knows whether the call worked, and defeats caches, proxies, and retry logic alike.


Return errors as problem+json

Every error body uses Content-Type: application/problem+json and the RFC 7807 shape, so one client-side handler covers every endpoint.

{
  "type": "https://example.com/errors/validation",
  "title": "Validation Failed",
  "status": 422,
  "detail": "3 fields failed validation",
  "instance": "/orders/123",
  "errors": [
    { "field": "email", "message": "Invalid format", "code": "INVALID_EMAIL" }
  ]
}
FieldRequiredMeaning
typeYesURI identifying the problem class, stable across releases
titleYesShort human-readable summary of the class
statusYesThe HTTP status code, repeated for clients that lost it
detailNoWhat went wrong on this occurrence
instanceNoURI of this specific occurrence
errorsNoExtension array of field-level failures

Fail: a body carrying a stack trace, an SQL fragment, or an upstream vendor's error text. detail is for the caller, not for your logs.


Wrap success responses in a consistent envelope

{
  "data": [{ "id": "abc-123", "name": "Alice" }],
  "meta": { "has_next": true, "next_cursor": "eyJpZCI6MTQzfQ" },
  "links": { "self": "/api/v1/users?limit=20", "next": "/api/v1/users?limit=20&cursor=eyJpZCI6MTQzfQ" }
}

A data wrapper leaves room to add meta and links later without breaking clients, which is why it suits public APIs. Returning the bare resource is fine for an internal API, provided every endpoint does it. What is never fine is mixing the two across one surface.

Cursor pagination is the default for any collection that grows without bound. Offset is for small fixed sets. The mechanics, plus filtering and sorting, are in references/pagination-and-filtering.md.


Require an idempotency key on non-idempotent writes

A client that times out cannot tell a lost request from a lost response. Give it a safe way to retry.

POST /api/v1/orders
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
  • A request with no key returns 400 with a problem body whose type links to the documentation.
  • Store the response for 24 hours, keyed by the idempotency key.
  • The same key with the same request body replays the stored response without re-executing.
  • The same key with a different body returns 422.

Support conditional requests on cacheable reads

Return ETag and Last-Modified on cacheable GETs, and honour If-None-Match and If-Modified-Since with a 304. The same ETag in If-Match on a PUT or PATCH gives you optimistic concurrency for free: a mismatch is a 412.

HTTP/1.1 200 OK
ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"
Last-Modified: Tue, 15 Jan 2025 10:30:00 GMT

Return 207 from bulk endpoints, and bound the batch

Use POST /resources/batch for bulk work and report per-item outcomes, because one failed item must not discard the other ninety-nine.

{
  "results": [
    { "id": "1", "status": 201, "data": {} },
    { "id": "2", "status": 422, "error": "Invalid email" }
  ]
}

Cap the number of items and the body size, and return 413 when a caller exceeds either. Process atomically when the domain requires it, and say which behaviour applies in the documentation.


Keep liveness and readiness separate

This section is the canonical definition of the health endpoint paths for this repository. Other skills probe or implement these two paths and must not rename them.

GET /health   liveness:  200 while the process runs, checks nothing external
GET /ready    readiness: 200 when dependencies are usable, 503 otherwise
{ "status": "degraded", "checks": { "db": "ok", "redis": "timeout" } }

Both sit outside the versioned path, because they describe the process rather than the API. Fail: one /health that checks the database, so a transient outage makes the orchestrator restart a perfectly healthy process.


Advertise rate limits on every response

This section is the canonical definition of the rate-limit headers and tiers for this repository. Other skills implement it and must not restate the values.

HTTP/1.1 200 OK
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1714000000
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1714000000
Retry-After: 60
Content-Type: application/problem+json

{ "type": "https://example.com/errors/rate-limit-exceeded", "title": "Too Many Requests", "status": 429 }

X-RateLimit-Reset is a UTC epoch in seconds. Send the three headers on successful responses too, because a client cannot back off from a budget it cannot see.

TierLimitWindowApplies to
Anonymous30/minPer IPPublic endpoints
Authenticated100/minPer userStandard API access
Premium1000/minPer API keyPaid plans
Internal10000/minPer serviceService-to-service calls

Version in the path, and announce every retirement

Put the version in the URL, keep at most two active versions, and give a deprecated one at least six months. Announce the end on the response with Deprecation and Sunset, then return 410 Gone after the date. The full policy, including which changes need a version at all, is in references/versioning.md.


Related skills

  • backend-patterns for idempotency storage, retries, and readiness behind the contract.
  • node-backend-patterns and springboot-patterns for handler-level implementations.
  • hexagonal-architecture for keeping transport concerns out of the domain.
  • security-review before exposing an endpoint that touches credentials, payments, or personal data.
  • soap-webservices when the contract is WSDL rather than HTTP and JSON.
  • observability-and-logging for correlating a request identifier across services.

Checklist

  • Resource URLs are plural, kebab-case nouns with no verbs outside genuine state transitions.
  • The method matches the semantics, and PATCH bodies describe a target state.
  • Status codes are used semantically, never 200 for a failure.
  • Every error body is application/problem+json and leaks no internal detail.
  • The success envelope is consistent across every endpoint on the surface.
  • List endpoints paginate, default to cursors when unbounded, and cap page size server-side.
  • Non-idempotent POST and PATCH require Idempotency-Key.
  • Cacheable GETs return ETag and Last-Modified and honour the conditional headers.
  • Bulk endpoints return 207 with per-item results and bound the batch.
  • /health and /ready exist, are separate, and sit outside the versioned path.
  • X-RateLimit-* headers are on every rate-limited response, with Retry-After on the 429.
  • Deprecated endpoints carry Deprecation and Sunset and return 410 after the date.
  • Input is schema-validated and authorization is checked per resource, not only per role.
  • The OpenAPI description is updated in the same change as the endpoint.

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.