agentleFS
CodeWithBehnamCodeWithBehnam/cc-docs/skills/api-conventions/SKILL.md

api-conventions

Skill2 starsChanged 9 months agoMITView on GitHub

REST API design conventions and standards. Apply when writing, reviewing, or discussing API endpoints, routes, controllers, serializers, or HTTP handlers. Covers URL structure, HTTP methods, response formats, error handling, pagination, versioning, and authentication headers.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. 0 are common, 7 are distinctive, and 10 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

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

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

    Use kebab-case for URL path segments: /user-profiles, not /userProfiles or /user_profiles

    line 13
  2. Very specific:

    Use plural nouns for resource collections: /orders, /products, /users

    line 14
  3. Very specific:

    Never use verbs in URLs. The HTTP method is the verb: DELETE /sessions/{id} not POST /logout

    line 16
  4. Very specific:

    Use POST /resources to create.

    line 29
  5. Very specific:

    Use PATCH for partial updates, not PUT, unless clients always send the full representation.

    line 30
  6. Distinctive:

    All responses use JSON. Property names use camelCase:

    line 34
  7. Very specific:

    Use a machine-readable code (snake_case string) for programmatic handling

    line 69
  8. Very specific:

    Use a human-readable message for display

    line 70
  9. Very specific:

    Always include requestId for support and tracing

    line 71
  10. Distinctive:

    Never return 200 with an error body.

    line 89
  11. Distinctive:

    Use cursor-based pagination for all list endpoints returning potentially large data:

    line 93
  12. Distinctive:

    Default page size: 25. Maximum: 100.

    line 111
  13. Distinctive:

    Use offset pagination only for admin UIs where jumping to a page is required.

    line 112
  14. Very specific:

    Use Authorization: Bearer <token> for API keys and JWT tokens

    line 123
  15. Distinctive:

    Never put tokens in URL query parameters (they appear in server logs)

    line 124
  16. Very specific:

    Use WWW-Authenticate header in 401 responses

    line 126
  17. Distinctive:

    Always return these headers:

    line 143

“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

URL Design

  • Use kebab-case for URL path segments: /user-profiles, not /userProfiles or /user_profiles
  • Use plural nouns for resource collections: /orders, /products, /users
  • Nest resources at most one level deep: /orders/{id}/items is fine; /orders/{id}/items/{id}/notes is too deep - promote notes to a top-level resource
  • Never use verbs in URLs. The HTTP method is the verb: DELETE /sessions/{id} not POST /logout
  • Resource IDs go in the path; filters go in query params: GET /products?category=books&min_price=10

HTTP Methods

MethodSemanticsIdempotentSafe
GETRead resource(s)YesYes
POSTCreate resource or trigger actionNoNo
PUTReplace resource entirelyYesNo
PATCHPartial updateNoNo
DELETERemove resourceYesNo
  • Use POST /resources to create. Return 201 Created with Location header pointing to the new resource.
  • Use PATCH for partial updates, not PUT, unless clients always send the full representation.

Response Format

All responses use JSON. Property names use camelCase:

{
  "id": "ord_01HXZ",
  "userId": "usr_abc",
  "status": "pending",
  "createdAt": "2025-03-15T10:00:00Z",
  "items": [
    { "productId": "prd_xyz", "quantity": 2, "unitPrice": 9.99 }
  ]
}
  • Dates and times are ISO 8601 in UTC: "2025-03-15T10:00:00Z"
  • IDs are strings (never expose raw database integer IDs)
  • Monetary amounts are integers in the smallest currency unit (cents), with a separate currency field
  • Booleans use true/false (not 0/1 or "yes"/"no")
  • Omit null fields by default; include them only when the absence is meaningful

Error Responses

{
  "error": {
    "code": "validation_error",
    "message": "Request validation failed",
    "details": [
      { "field": "email", "issue": "Must be a valid email address" }
    ],
    "requestId": "req_01HXZ"
  }
}
  • Use a machine-readable code (snake_case string) for programmatic handling
  • Use a human-readable message for display
  • Always include requestId for support and tracing

HTTP Status Codes

CodeWhen to use
200Successful GET, PATCH, or DELETE with body
201Successful POST that created a resource
204Successful DELETE or action with no response body
400Client sent an invalid request (validation errors)
401Authentication required or invalid credentials
403Authenticated but not authorized for this resource
404Resource not found (or deliberately hidden)
409Conflict (duplicate, optimistic lock failure)
422Request is valid JSON but semantically wrong
429Rate limit exceeded
500Unexpected server error

Never return 200 with an error body.

Pagination

Use cursor-based pagination for all list endpoints returning potentially large data:

GET /orders?limit=25&cursor=eyJpZCI6IjEwMCJ9

Response:

{
  "data": [ ... ],
  "pagination": {
    "limit": 25,
    "nextCursor": "eyJpZCI6IjEyNSJ9",
    "hasMore": true
  }
}
  • Default page size: 25. Maximum: 100.
  • Use offset pagination only for admin UIs where jumping to a page is required.

Versioning

  • Version in the URL path: /v1/orders, /v2/orders
  • Increment the major version only for breaking changes (removed fields, changed semantics)
  • Deprecate old versions with a Deprecation response header; support them for at least 12 months
  • New optional fields added to responses are non-breaking and do not require a version bump

Authentication

  • Use Authorization: Bearer <token> for API keys and JWT tokens
  • Never put tokens in URL query parameters (they appear in server logs)
  • For API keys: prefix them with a product identifier for easy detection: sk_live_..., pk_test_...
  • Use WWW-Authenticate header in 401 responses

Filtering, Sorting, and Searching

  • Filters: GET /products?status=active&category=books
  • Sorting: GET /orders?sort=createdAt&order=desc (default to asc)
  • Full-text search: GET /products?q=wireless+headphones
  • Range filters: GET /orders?createdAfter=2025-01-01&createdBefore=2025-03-01

Idempotency

  • Accept an Idempotency-Key header on POST requests that create resources or trigger payments
  • Store the key and return the same response if the same key is replayed within 24 hours
  • Return 409 Conflict if the same key is used with a different request body

Rate Limiting

Always return these headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 487
X-RateLimit-Reset: 1741694400
Retry-After: 30  (only on 429)

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.