Agent-skills-standard common-api-design
Apply REST API conventions — HTTP semantics, status codes, versioning, pagination, and OpenAPI standards for any framework. Use when designing endpoints, choosing HTTP methods, implementing pagination, or writing OpenAPI specs. (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/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/common/common-api-design" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-common-api-design && rm -rf "$T"
manifest:
skills/common/common-api-design/SKILL.mdsource content
Common API Design Standards
Priority: P1 (OPERATIONAL)
🔧 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 default:
,/v1/users
./v2/users - Header versioning (
) acceptable for internal APIs.Api-Version: 2 - Never mix versions in same controller — each version gets its own route module.
- Support prev major ≥ 6 months after new release.
- Deprecation:
+Deprecation: true
headers when 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
- Generate from code annotations — not hand-written YAML.
- Every API needs OpenAPI 3.1 spec.
- Include: request/response schemas, error shapes, auth requirements, examples.
- Review spec in PR — breaking changes need 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 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.