api-design
Design clean REST/JSON APIs — resources, status codes, errors, versioning, pagination.
SKILL.mdskills/api-design/SKILL.md
GitHubWhen to use
The user is designing endpoints or asks for a review of an API surface.
How
- Resources are plural nouns (
/users/{id}/orders); verbs live in the HTTP method, not the path. Actions that fit no resource →POST /…/actions. - Status codes that mean what they say: 200/201/204 success; 400 malformed, 401 unauthenticated, 403 forbidden, 404 missing, 409 conflict, 422 validation; 5xx only for server faults.
- One error envelope everywhere:
{"error": {"code": "machine_readable", "message": "human readable", "details": [...]}}. - Pagination on every list endpoint from day one (cursor preferred:
?cursor=…&limit=…→{"items": [...], "next_cursor": …}). - Version in the path (
/v1/) — and don't break v1 once published. - Request/response field naming consistent (pick snake_case or camelCase, never both). Timestamps ISO-8601 UTC.
- Idempotency: PUT/DELETE naturally; POST that charges/creates externally →
accept an
Idempotency-Keyheader.
Avoid
- 200 with
{"success": false}— that's a 4xx/5xx. - Unbounded list responses.
- Leaking internals (DB ids/stack traces) in error messages.
Done well
A consumer can predict every endpoint's shape from one example; errors are actionable; nothing breaks when you add fields later.