agentleFS
halflength-ampleness75halflength-ampleness75/claude-code-recipes/skills/api-design/SKILL.md

api-design

Skill2 starsChanged 7 months agoMITView on GitHub

REST API conventions: URL structure, HTTP methods, status codes, pagination, filtering, error responses, and versioning. *PATCH is not guaranteed idempotent, but should be designed to be when possible. Use the correct status code. When in doubt, refer to this table: Use a consistent error format across all endpoints: Use cursor-based pagination for large datasets, offset-based for simple cases.

125 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use data-modeling, ci-pipeline and 8 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

  • InfopibeSkill

    deployment-patterns

    Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications.

    Also in 10 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

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

  • 0

    Common

    Most of the 104 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the correct status code.

    line 49
  2. Distinctive:

    Use a consistent error format across all endpoints:

    line 81
  3. Distinctive:

    Use cursor-based pagination for large datasets, offset-based for simple cases.

    line 113

“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

REST API conventions: URL structure, HTTP methods, status codes, pagination, filtering, error responses, and versioning.

URL Structure

  1. Use nouns, not verbs — the HTTP method provides the verb
  2. Use plural resource names — /users, /orders, /products
  3. Use kebab-case for multi-word resources — /order-items, not /orderItems
  4. Nest resources to show relationships — max 2 levels deep
  5. Use query parameters for filtering, not path segments
# Good
GET    /api/v1/users
GET    /api/v1/users/123
GET    /api/v1/users/123/orders
POST   /api/v1/users
PATCH  /api/v1/users/123
DELETE /api/v1/users/123

# Bad
GET    /api/v1/getUsers
GET    /api/v1/user/123
POST   /api/v1/users/123/orders/456/items/789/notes   # too deeply nested

HTTP Methods

MethodPurposeIdempotentRequest BodySuccess Code
GETRead resource(s)YesNo200
POSTCreate resourceNoYes201
PUTReplace resource entirelyYesYes200
PATCHPartial updateNo*Yes200
DELETERemove resourceYesNo204

*PATCH is not guaranteed idempotent, but should be designed to be when possible.

Rules

  1. GET requests must be safe — no side effects, no state changes
  2. POST for creation — return the created resource with Location header
  3. Use PATCH over PUT — partial updates are more practical than full replacement
  4. DELETE should be idempotent — deleting a non-existent resource returns 204, not 404

Status Codes

Use the correct status code. When in doubt, refer to this table:

Success (2xx)

CodeMeaningWhen to Use
200OKSuccessful GET, PUT, PATCH
201CreatedSuccessful POST that creates a resource
204No ContentSuccessful DELETE, or PUT/PATCH with no response body

Client Errors (4xx)

CodeMeaningWhen to Use
400Bad RequestMalformed JSON, invalid field values, validation errors
401UnauthorizedMissing or invalid authentication
403ForbiddenAuthenticated but lacks permission
404Not FoundResource does not exist
409ConflictDuplicate resource, state conflict
422Unprocessable EntityValid JSON but fails business rules
429Too Many RequestsRate limit exceeded

Server Errors (5xx)

CodeMeaningWhen to Use
500Internal Server ErrorUnexpected server failure
502Bad GatewayUpstream service failure
503Service UnavailableServer overloaded or in maintenance

Error Responses

Use a consistent error format across all endpoints:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request validation failed.",
    "details": [
      {
        "field": "email",
        "message": "Must be a valid email address.",
        "code": "INVALID_FORMAT"
      },
      {
        "field": "age",
        "message": "Must be at least 18.",
        "code": "MIN_VALUE"
      }
    ]
  }
}

Rules

  1. Always include a machine-readable error code — VALIDATION_ERROR, NOT_FOUND, RATE_LIMITED
  2. Include a human-readable message — suitable for developer debugging
  3. Never expose internal errors — no stack traces, SQL queries, or file paths in production
  4. Field-level errors in details array — for validation errors, specify which field failed

Pagination

Use cursor-based pagination for large datasets, offset-based for simple cases.

Offset-based (simple)

GET /api/v1/users?page=2&per_page=25

Response:
{
  "data": [ ... ],
  "pagination": {
    "page": 2,
    "per_page": 25,
    "total": 150,
    "total_pages": 6
  }
}

Cursor-based (scalable)

GET /api/v1/users?limit=25&cursor=eyJpZCI6MTAwfQ

Response:
{
  "data": [ ... ],
  "pagination": {
    "limit": 25,
    "has_more": true,
    "next_cursor": "eyJpZCI6MTI1fQ"
  }
}

Rules

  1. Default page size: 25, max: 100 — prevent clients from requesting unlimited data
  2. Always return pagination metadata — clients need to know if there are more pages
  3. Use cursor-based for real-time data or large tables — offset-based breaks with concurrent writes

Filtering and Sorting

# Filter by field values
GET /api/v1/users?status=active&role=admin

# Date ranges
GET /api/v1/orders?created_after=2025-01-01&created_before=2025-12-31

# Search
GET /api/v1/products?q=keyboard

# Sort (prefix with - for descending)
GET /api/v1/users?sort=created_at
GET /api/v1/users?sort=-updated_at

# Combine everything
GET /api/v1/orders?status=shipped&sort=-created_at&page=1&per_page=25

Rules

  1. Use snake_case for query parameter names
  2. Support multiple sort fields — ?sort=-created_at,name
  3. Validate all filter parameters — return 400 for unknown fields
  4. Document allowed filter fields per endpoint

Request and Response Conventions

  1. Use snake_case for all JSON keys — created_at, first_name, order_id
  2. Use ISO 8601 for dates — 2025-06-15T14:30:00Z
  3. Use UUIDs or opaque strings for IDs — avoid exposing auto-increment integers
  4. Wrap collections in a data key — { "data": [...] }, not a bare array
  5. Include created_at and updated_at in all resources
  6. Use null for absent optional fields — don't omit them entirely
{
  "data": {
    "id": "usr_a1b2c3d4",
    "email": "user@example.com",
    "first_name": "Jane",
    "last_name": "Doe",
    "role": "admin",
    "avatar_url": null,
    "created_at": "2025-06-15T14:30:00Z",
    "updated_at": "2025-06-15T14:30:00Z"
  }
}

Versioning

  1. Use URL path versioning — /api/v1/, /api/v2/
  2. Increment the major version only for breaking changes
  3. Support the previous version for at least 6 months after deprecation
  4. Return a Deprecation header on deprecated endpoints
  5. Document migration guides between versions

Authentication

  1. Use Bearer tokens in the Authorization header — Authorization: Bearer <token>
  2. Never pass tokens in query parameters — they end up in server logs
  3. Return 401 for missing/invalid tokens, 403 for insufficient permissions
  4. Include rate limit headers — X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset

Anti-patterns

  • Verbs in URLs — use HTTP methods instead
  • Returning 200 with error body — use proper status codes
  • Nested resources deeper than 2 levels — flatten with query parameters
  • Inconsistent naming — pick snake_case or camelCase and stick with it
  • Missing pagination on list endpoints — always paginate collections
  • Exposing internal IDs — use prefixed opaque IDs like usr_, ord_, prod_

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.