Skillshub common-api-design
REST API conventions — HTTP semantics, status codes, versioning, pagination, and OpenAPI standards applicable to any framework. (triggers: **/*.controller.ts, **/*.router.ts, **/*.routes.ts, **/routes/**, **/controllers/**, **/handlers/**, rest api, endpoint, http method, status code, versioning, pagination, openapi, api design, api contract)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/common-api-design" ~/.claude/skills/comeonoliver-skillshub-common-api-design && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/common-api-design/SKILL.mdsource content
Common API Design Standards
Priority: P1 (OPERATIONAL)
Consistent, predictable API contracts reduce integration friction and prevent breaking changes from reaching consumers.
🔧 HTTP Verb Semantics
read-only, idempotent — never mutates state.GET
create or trigger;POST
full replace;PUT
partial update;PATCH
remove.DELETE- Non-CRUD actions as sub-resources:
.POST /orders/:id/cancel
📡 Status Code Correctness
success;200
created (add201
header);Location
no body.204
validation (with400
);details[]
unauthenticated;401
unauthorized;403
not found.404
conflict;409
business rule violation;422
rate limit (add429
);Retry-After
unhandled.500
📦 URL Design Rules
- Lowercase, kebab-case:
, not/user-profiles
or/UserProfiles
./user_profiles - Plural nouns:
,/orders
. Not/products
,/order
./getProducts - No verbs in paths (except action sub-resources):
✅,/orders/:id/cancel
❌./cancelOrder - Hierarchy: Use nesting only up to 2 levels:
✅,/users/:id/orders
❌./users/:id/orders/:orderId/items/:itemId
🔢 API Versioning
- Strategy: URL path versioning is the default:
,/v1/users
./v2/users - Header versioning (
) is acceptable for internal APIs.Api-Version: 2 - Never mix versions in the same controller — each version gets its own route module.
- Support previous major version for minimum 6 months after a new one is released.
- Deprecation: Add
+Deprecation: true
headers when a version will be retired.Sunset: <date>
📄 Pagination
- Prefer cursor-based (
+cursor
) for large/live datasets; offset only for small static ones.limit - Default
, maxlimit: 20
. Reject requests exceeding max.100 - Response envelope:
.{ data: [], pagination: { nextCursor, hasNextPage } }
📝 OpenAPI Contract
- Every API MUST have an OpenAPI 3.1 spec.
- Generate spec from code annotations (not hand-written YAML) to prevent drift.
- Include: request/response schemas, error shapes, auth requirements, examples.
- Review OpenAPI spec as part of PR process — breaking changes require version bump.
🔒 API Security Baseline
- Require auth on all routes by default; use
or equivalent opt-out.@Public() - Validate and sanitize all query params, path params, and request bodies.
- Set
explicitly. Reject unexpected content types.Content-Type: application/json - Include
andX-Content-Type-Options: nosniff
headers.X-Frame-Options: DENY
Anti-Patterns
- No
mutations: Search engines and CDNs cache GET — mutating state is catastrophic.GET - No 200 for errors:
with HTTP 200 breaks monitoring.{ "success": false, "data": null } - No deeply nested URLs: Hard to document, version, and cache.
- No breaking changes without versioning: Removing/renaming fields in-place breaks consumers silently.