agentleFS
jars-demojars-demo/jars-skills/skills/api-design/SKILL.md

api-design

Skill0 starsChanged 32 days agoMITView on GitHub

Design clean, consistent HTTP APIs. Use when the user asks to design an endpoint, review an API contract, add a new route, define request/response shapes, write an OpenAPI spec, or decide on REST vs GraphQL vs RPC for a feature.

191 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use db-design, everything-claude-code and 10 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.
  • yuexueyuSkill

    db-design

    数据库工程师技能 - Schema设计、索引优化、并发安全、数据库审计。当你涉及数据库表/字段/索引/SQL/迁移/MCP数据库操作、建表改表、写查询时必须使用此技能。即使用户只是说"加个字段"或"查下数据",也应触发。

    Also in 4 projects that use this

  • InfopibeSkill

    everything-claude-code

    Also in 9 projects that use this

  • mryeastcodeSkill

    everything-claude-code-conventions

    Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

    Also in 8 projects that use this

  • tpavanipradeepSkill

    nextjs-turbopack

    Next.js 16+ and Turbopack — incremental bundling, FS caching, dev speed, and when to use Turbopack vs webpack.

    Also in 15 projects that use this

  • Indium-AI-LabsSkill

    data-pipeline-design

    Design batch or incremental ETL and ELT pipelines and warehouse models: grain, partitioning, idempotent loads, late-arriving data, data quality tests, PII controls, and cost monitoring, before building them. Use when adding or changing a dbt model, warehouse table, scheduled transformation, or ingestion job. Not for transactional schema design (use the database-design skill) or event-sourced stores (use the event-sourcing-architecture skill).

    Also in 3 projects that use this

  • thejordanleopoldSkill

    third-party-integration

    Use when integrating with external APIs, payment processors (Stripe), webhooks, or third-party services. Use when implementing API clients with authentication and rate limiting, handling webhooks with signature verification and idempotency, writing contract tests for external services, or isolating third-party dependencies behind adapters. Triggers: \"Stripe\", \"payment integration\", \"webhook\", \"third-party API\", \"external service\", \"API client\", \"integrate with\", \"signature verification\", \"idempotency key\".

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 10 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 165 edited versions we read keep these.

  • 10

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Be boring: Use the HTTP method and status code the spec actually defines.

    line 17
  2. Distinctive:

    Ask (or find in context):

    line 36
  3. Very specific:

    No verbs in the URL (except action sub-routes): /users/{id}/activate, not /activateUser.

    line 61
  4. Distinctive:

    No trailing slashes unless the existing API uses them.

    line 62
  5. Very specific:

    Add minLength, maxLength, minimum, maximum, pattern, enum for every field that has a natural constraint.

    line 91
  6. Distinctive:

    Never accept raw HTML, SQL, or executable content unless the endpoint exists specifically to process it, and even then sanitise it.

    line 94
  7. Very specific:

    Never return a 200 with { "success": false }.

    line 137
  8. Distinctive:

    Check whether the existing service uses API keys, JWT, OAuth 2, session cookies, or mTLS.

    line 141
  9. Distinctive:

    Update the OpenAPI/Swagger file, or create one if none exists:

    line 161
  10. Distinctive:

    All parameters with types and descriptions

    line 171
  11. Distinctive:

    All possible response codes with example bodies

    line 172
  12. Distinctive:

    Before implementation, share the spec with whoever will consume the API (or re-read it as if you are the caller):

    line 176
  13. Distinctive:

    If the answer to any is "no", revise the spec.

    line 183

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

Design APIs that are easy to consume, hard to misuse, and consistent enough that a new developer can guess the next endpoint before reading the docs.

Ground rules

  • Read what already exists. Grep for existing routes, OpenAPI/Swagger files, GraphQL schemas, or REST conventions before proposing anything new. New endpoints must fit the existing style.
  • One resource, one URL. Each endpoint does one thing. An endpoint that "creates and also sends an email and optionally deletes the old one" is three jobs — split it.
  • Be boring. Use the HTTP method and status code the spec actually defines. Do not invent new conventions when standard ones exist.
  • Design the contract before writing the handler. Agree on the URL, method, request shape, and response shape first. The implementation follows the contract, not the other way around.
  • Never break a published contract without versioning. Additive changes (new optional fields) are usually fine; removing or renaming fields is a breaking change.

Workflow

1. Understand the context

# Find existing routes
grep -rn "router\.\|app\.\|@app\.\|Route\|path=" src/ --include="*.py" --include="*.ts" --include="*.js"

# Find the OpenAPI or API description file
find . -name "openapi*.yaml" -o -name "openapi*.json" -o -name "swagger*.yaml" | head -5

Ask (or find in context):

  • What resource does this endpoint act on?
  • Who calls it — a browser, a mobile client, another service?
  • What authentication scheme is already in use?
  • Does the project use REST, GraphQL, tRPC, gRPC, or something else?

2. Pick the right method and URL

For REST follow these conventions without deviation:

ActionMethodURL
List a collectionGET/resources
Get one itemGET/resources/{id}
CreatePOST/resources
Full replacePUT/resources/{id}
Partial updatePATCH/resources/{id}
DeleteDELETE/resources/{id}
Sub-resourceGET/POST/resources/{id}/sub
Non-CRUD actionPOST/resources/{id}/action-name

URL rules:

  • Lowercase, hyphen-separated words: /payment-methods, not /paymentMethods.
  • Plural nouns for collections: /orders, not /order.
  • No verbs in the URL (except action sub-routes): /users/{id}/activate, not /activateUser.
  • No trailing slashes unless the existing API uses them.
  • Resource nesting only one level deep: /orders/{id}/items yes; /orders/{id}/items/{iid}/tags — flatten it.

3. Define the request shape

For every non-GET endpoint, define:

# Example in OpenAPI 3 style
requestBody:
  required: true
  content:
    application/json:
      schema:
        type: object
        required: [name, email]
        properties:
          name:
            type: string
            minLength: 1
            maxLength: 255
          email:
            type: string
            format: email
        additionalProperties: false

Rules:

  • Mark every field required or optional explicitly. Implicit optionality hides bugs.
  • Add minLength, maxLength, minimum, maximum, pattern, enum for every field that has a natural constraint.
  • additionalProperties: false prevents clients from sending junk that gets silently ignored.
  • Never accept raw HTML, SQL, or executable content unless the endpoint exists specifically to process it, and even then sanitise it.

4. Define the response shape

Pick the right status code:

SituationCode
Successful GET, PATCH, PUT200 OK
Created resource201 Created + Location: /resources/{id} header
Accepted for async processing202 Accepted
Successful DELETE with no body204 No Content
Bad input (client error)400 Bad Request + error body
Missing or invalid credentials401 Unauthorized
Valid credentials, wrong permissions403 Forbidden
Resource not found404 Not Found
Method not allowed405 Method Not Allowed
Conflict (duplicate, state mismatch)409 Conflict
Validation failed422 Unprocessable Entity
Server error500 Internal Server Error

Return consistent error bodies:

{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "name is required",
    "fields": { "name": "required" }
  }
}

Return consistent success bodies. For collections, include pagination metadata:

{
  "data": [...],
  "meta": { "total": 84, "page": 2, "pageSize": 20 }
}

Never return a 200 with { "success": false }. Use the status code.

5. Handle auth and permissions

  • Check whether the existing service uses API keys, JWT, OAuth 2, session cookies, or mTLS. Match it — do not introduce a second auth scheme.
  • Authorisation belongs in the handler or a middleware, never in the URL (/admin/users is a smell — use middleware to check roles).
  • Return 401 when identity is missing or invalid, 403 when the identity is known but not allowed. Never swap them.

6. Design for change

Before finalising:

  • Could a field name be mistaken for another? Rename it.
  • Could a required field become optional later without a breaking change? Make it optional now.
  • Is the response returning more data than the caller needs? Consider a fields query param or a dedicated summary shape.
  • Does the endpoint need to be called in a loop? Consider a batch variant.
  • Will the resource list grow unbounded? Add cursor- or offset-based pagination from day one.

7. Document it

Update the OpenAPI/Swagger file, or create one if none exists:

# Validate an OpenAPI file
npx @redocly/cli lint openapi.yaml

At minimum, each endpoint needs:

  • A summary (one sentence)
  • A description for any non-obvious behaviour
  • All parameters with types and descriptions
  • All possible response codes with example bodies

8. Review the contract

Before implementation, share the spec with whoever will consume the API (or re-read it as if you are the caller):

  • Can you build a client from this spec alone, without reading the implementation?
  • Are the error codes specific enough to act on?
  • Would a new developer guess the next endpoint correctly?

If the answer to any is "no", revise the spec.

Common mistakes to avoid

MistakeCorrect approach
Tunnelling everything through POST /api/doUse resource URLs and the right method
Returning 500 for validation errorsReturn 400 or 422 with field details
Swallowing auth errors as 404 to "hide" resourcesReturn 403; hiding is security theatre
Nesting resources three levels deepFlatten: expose the leaf resource directly
Mutable resource IDsIDs are permanent; if a slug changes, keep an alias
Skipping pagination on list endpointsEvery collection endpoint needs pagination
Returning the whole record after every mutationReturn the updated record or 204; let the client decide if it needs to re-fetch

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.