rest-api-best-practices
Skill5 starsChanged 30 days agoMITView on GitHub
Use when designing or reviewing REST resources, methods, status codes, errors, pagination, filtering, versioning, authorization, idempotency, or public compatibility. Expose domain capabilities while preserving existing HTTP contracts; use the domain and infrastructure skills for implementation rules.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- CodeCaroS/MythOs_Aegistheir own version, first seen Aug 11, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- CodeCaroS/MythOs_Aegis★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- boostSkill
- data-migration-best-practicesSkill
- ddd-best-practicesSkill
- design-patterns-best-practicesSkill
- flowSkill
- fp-best-practicesSkill
- infrastructure-designSkill
- oop-best-practicesSkill
- refactoring-best-practicesSkill
- tdd-best-practicesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
48 rules. About 0 are common, 21 are distinctive, and 27 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈21
Distinctive · estimate
This author's own choices. Worth a look.
27
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Use this skill when the main question is how to design, review, or improve a REST API — from URL structure to error formats to security.
- Distinctive: line 16
Start from what the consumer needs, not from what the database looks like.
- Distinctive: line 17
Use HTTP as designed — methods, status codes, and headers carry meaning.
- Distinctive: line 27
Use resource nouns; model a non-CRUD domain action as a task subresource when the contract calls for it.
- Distinctive: line 32
PUT for full replacement (idempotent)
- Distinctive: line 34
DELETE for removal (idempotent)
- Distinctive: line 37
Keep paths flat where possible — at most two levels of nesting.
- Distinctive: line 38
Use query parameters for filtering, sorting, and pagination.
- Very specific: line 39
Use task URLs (POST /orders/{id}/cancel) for domain operations that aren't simple CRUD.
- Distinctive: line 44
Use HTTP headers for metadata (pagination, rate limits).
- Distinctive: line 47
Use the right 4xx or 5xx status code — never return 200 for errors.
- Distinctive: line 49
Follow RFC 9457 (Problem Details, which obsoletes RFC 7807) when the team needs a standard.
- Very specific: line 52
Default to URL versioning (/v1/).
- Distinctive: line 53
Treat a breaking change as a reason to bump the version, not to patch silently.
- Very specific: line 70
Default to cursor-based for large or real-time datasets.
- Very specific: line 77
Avoid exposing raw CRUD when the domain has real business operations.
- Distinctive: line 81
Use plural nouns for collection endpoints.
- Very specific: line 82
Avoid transport-operation names such as /getUsers.
- Distinctive: line 86
Never expose stack traces, SQL errors, or internal paths in error responses.
- Very specific: line 88
Use Accept and Content-Type headers for content negotiation.
- Distinctive: line 89
Put secrets in headers, never in query parameters.
- Distinctive: line 90
Always use HTTPS — never plain HTTP for API traffic.
- Distinctive: line 95
Every status code is intentional and precise.
- Distinctive: line 108
Every endpoint maps directly to a database table with full CRUD.
- Distinctive: line 109
No versioning strategy — breaking changes deployed silently.
- Distinctive: line 112
No request ID header — errors cannot be correlated in logs.
- Distinctive: line 113
No documentation or documentation that doesn't match reality.
- Very specific: line 117
Read references/retry-contracts.md when defining idempotency, unknown outcomes, or compatibility of published behavior.
- Very specific: line 119
Read references/url-design.md for URL structure, naming conventions, nesting rules, versioning, and task-based URLs.
- Very specific: line 120
Read references/http-semantics.md for HTTP method semantics, idempotency, safety, status code selection, and key headers.
- Very specific: line 121
Read references/request-response-design.md for filtering, sorting, pagination (offset and cursor), content negotiation, and response shape.
- Very specific: line 122
Read references/error-handling.md for RFC 9457 Problem Details, centralized mapping, status policy, redaction, domain failure translation, …
- Very specific: line 123
Read references/security.md for authentication (JWT, API keys, OAuth 2.0), authorization, rate limiting, CORS, and HTTPS enforcement.
- Very specific: line 124
Read references/api-design-philosophy.md for REST architectural constraints, the CRUD anti-pattern, task-based API design, and HATEOAS.
- Very specific: line 125
Read references/observability.md for request IDs, structured logging, metrics, distributed tracing, health endpoints, and alerting.
- Very specific: line 126
Read references/documentation.md for what to document per endpoint, working examples, OpenAPI 3.x spec structure, keeping docs executable …
- Very specific: line 127
Read references/caching.md for Cache-Control directives, ETag/Last-Modified validation, conditional writes (optimistic concurrency), cache …
- Very specific: line 128
Read references/testing-apis.md for the API test pyramid, contract testing (OpenAPI, Pact), what to test beyond the happy path, and test …
- Very specific: line 129
Read references/language-examples.md for an index of language-specific implementation examples.
- Very specific: line 130
Read references/typescript-examples.md for REST API implementation in TypeScript (Express, NestJS).
- Very specific: line 131
Read references/python-examples.md for REST API implementation in Python (FastAPI, Django REST Framework).
- Very specific: line 132
Read references/go-examples.md for REST API implementation in Go (net/http, Chi).
- Very specific: line 133
Read references/php-examples.md for REST API implementation in PHP (Laravel, Symfony).
- Very specific: line 134
Read references/java-examples.md for REST API implementation in Java (Spring Boot 3.x).
- Very specific: line 135
Read references/rust-examples.md for REST API implementation in Rust (axum).
- Very specific: line 139
Use ddd-best-practices when the API surface should reflect a Bounded Context or align with domain language.
- Very specific: line 140
Use design-patterns-best-practices for internal patterns within the API implementation (Repository, Service Layer, etc.).
- Very specific: line 141
Use oop-best-practices for controller and service design within the API layer.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
REST API Best Practices
Use this skill when the main question is how to design, review, or improve a REST API — from URL structure to error formats to security.
Working Style
- Start from what the consumer needs, not from what the database looks like.
- Use HTTP as designed — methods, status codes, and headers carry meaning.
- Express domain capabilities, not data operations.
- Make errors as informative as successes.
- Design for change: version early, break compatibility deliberately.
Design Workflow
- Define the resources.
- What are the concepts the consumer needs to interact with?
- Name them with nouns, in plural form.
- Use resource nouns; model a non-CRUD domain action as a task subresource when the contract calls for it.
- Choose the right HTTP method.
- GET for retrieval (safe, idempotent, cacheable)
- POST for creation or non-idempotent operations
- PUT for full replacement (idempotent)
- PATCH for partial update
- DELETE for removal (idempotent)
- Design the URL.
- Keep paths flat where possible — at most two levels of nesting.
- Use query parameters for filtering, sorting, and pagination.
- Use task URLs (
POST /orders/{id}/cancel) for domain operations that aren't simple CRUD.
- Define response shapes.
- Choose a consistent field naming convention (camelCase or snake_case) and stick to it.
- Return only what the consumer needs.
- Use HTTP headers for metadata (pagination, rate limits).
- Define error responses.
- Use the right 4xx or 5xx status code — never return 200 for errors.
- Return a structured error body with a machine-readable code and a human-readable message.
- Follow RFC 9457 (Problem Details, which obsoletes RFC 7807) when the team needs a standard.
- Add versioning.
- Default to URL versioning (
/v1/). - Treat a breaking change as a reason to bump the version, not to patch silently.
- Default to URL versioning (
Heuristics
Resource Naming
Nouns, plural, lowercase, kebab-case for multi-word: /user-profiles, /order-items.
HTTP Method Semantics
GET is safe and must never change state. POST creates or triggers actions. PUT replaces the entire resource. PATCH patches specific fields. DELETE removes.
Status Code Choice
2xx = success. 4xx = client error. 5xx = server error. Never return 200 for a failed operation.
Error Format
One consistent error envelope for all failures. Machine-readable code field, human-readable message, optional errors array for field-level validation details.
Pagination
Default to cursor-based for large or real-time datasets. Offset-based is fine for small, bounded collections. Always include a Link header with navigation links.
Retry safety
A key belongs to one logical intent and remains stable across retries. Define atomic claim, payload binding, replay authorization, in-flight behavior, and retention before calling a write retry-safe.
CRUD vs. Task-Based Design
Avoid exposing raw CRUD when the domain has real business operations. Prefer POST /orders/{id}/cancel over PATCH /orders/{id} with { "status": "cancelled" }.
Day-to-Day Rules
- Use plural nouns for collection endpoints.
- Avoid transport-operation names such as
/getUsers; an intentional task subresource such as/orders/{id}/cancelis valid. - Return 201 Created (not 200) after a successful POST that creates a resource.
- Include a
Locationheader pointing to the new resource after 201. - Return 204 No Content when there is nothing meaningful to return in the body.
- Never expose stack traces, SQL errors, or internal paths in error responses.
- Paginate every collection endpoint — never return an unbounded list.
- Use
AcceptandContent-Typeheaders for content negotiation. - Put secrets in headers, never in query parameters.
- Always use HTTPS — never plain HTTP for API traffic.
Good Signals
- URL paths read like a sentence:
GET /orders/{id}/items. - Every status code is intentional and precise.
- Errors have a machine-readable code the client can branch on.
- Pagination is consistent across all collection endpoints.
- Breaking changes require a version bump.
- The API surface reflects domain language, not table names.
Warning Signs
- Verbs in URL paths:
/getUser,/createOrder,/deleteItem. - 200 OK returned for validation errors or business failures.
- Error bodies expose stack traces or raw SQL.
- Collections returned without pagination.
- Inconsistent field naming: sometimes
userId, sometimesuser_id. - Every endpoint maps directly to a database table with full CRUD.
- No versioning strategy — breaking changes deployed silently.
- API key or token passed as a query parameter.
- Response objects nested more than two levels deep.
- No request ID header — errors cannot be correlated in logs.
- No documentation or documentation that doesn't match reality.
References
- Read
references/retry-contracts.mdwhen defining idempotency, unknown outcomes, or compatibility of published behavior. - Read
references/url-design.mdfor URL structure, naming conventions, nesting rules, versioning, and task-based URLs. - Read
references/http-semantics.mdfor HTTP method semantics, idempotency, safety, status code selection, and key headers. - Read
references/request-response-design.mdfor filtering, sorting, pagination (offset and cursor), content negotiation, and response shape. - Read
references/error-handling.mdfor RFC 9457 Problem Details, centralized mapping, status policy, redaction, domain failure translation, and validation errors. - Read
references/security.mdfor authentication (JWT, API keys, OAuth 2.0), authorization, rate limiting, CORS, and HTTPS enforcement. - Read
references/api-design-philosophy.mdfor REST architectural constraints, the CRUD anti-pattern, task-based API design, and HATEOAS. - Read
references/observability.mdfor request IDs, structured logging, metrics, distributed tracing, health endpoints, and alerting. - Read
references/documentation.mdfor what to document per endpoint, working examples, OpenAPI 3.x spec structure, keeping docs executable with contract testing, and changelog practices. - Read
references/caching.mdfor Cache-Control directives, ETag/Last-Modified validation, conditional writes (optimistic concurrency), cache layers, and invalidation strategies. - Read
references/testing-apis.mdfor the API test pyramid, contract testing (OpenAPI, Pact), what to test beyond the happy path, and test isolation. - Read
references/language-examples.mdfor an index of language-specific implementation examples. - Read
references/typescript-examples.mdfor REST API implementation in TypeScript (Express, NestJS). - Read
references/python-examples.mdfor REST API implementation in Python (FastAPI, Django REST Framework). - Read
references/go-examples.mdfor REST API implementation in Go (net/http, Chi). - Read
references/php-examples.mdfor REST API implementation in PHP (Laravel, Symfony). - Read
references/java-examples.mdfor REST API implementation in Java (Spring Boot 3.x). - Read
references/rust-examples.mdfor REST API implementation in Rust (axum).
Related Skills
- Use
ddd-best-practiceswhen the API surface should reflect a Bounded Context or align with domain language. - Use
design-patterns-best-practicesfor internal patterns within the API implementation (Repository, Service Layer, etc.). - Use
oop-best-practicesfor controller and service design within the API layer.
Source Influences
This skill is synthesized from:
- REST API Design Rulebook by Mark Masse
- RESTful Web APIs by Leonard Richardson & Mike Amundsen
- RFC 9457 — Problem Details for HTTP APIs
- RFC 9110 — HTTP Semantics
- Fran Iglesias — API REST series (franiglesias.github.io)
- Derek Comartin — "CRUD APIs are Poor Design" (codeopinion.com)
- Postman REST API Best Practices
- Building Microservices by Sam Newman
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
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.

