REST APIs MUST be intuitive, predictable, and semantically correct. This skill ensures APIs use HTTP methods correctly, communicate errors clearly via standard formats, and maintain consistency across resources so clients can interact with them reliably without surprise behavior.
When to use
Building a new backend service exposing resources
Adding a new domain entity to an existing API
Creating integration endpoints for third-party partners
Designing webhooks or callback mechanisms
Standardizing an inconsistent API across a microservices architecture
Agent MUST NEVER: Use verbs in URLs, return 200 for errors, nest beyond 2 levels, mix status code semantics
Agent MUST ASK: Before changing versioning strategy, before modifying existing endpoint contracts
Agent MUST VALIDATE: All status codes correct, no URL verbs, pagination present, RFC 7807 errors
Example
❌ Anti-pattern (Verbs in URL, wrong status codes, deep nesting, no pagination):
GET /api/getUsers HTTP/1.1
HTTP/1.1 200 OK
{
"status": "error",
"message": "User not found"
}
GET /api/companies/123/departments/456/employees/789/tasks/assignToUser HTTP/1.1
GET /v1/users?limit=20&offset=0 HTTP/1.1
HTTP/1.1 200 OK
{
"data": [...],
"pagination": {
"limit": 20,
"offset": 0,
"total": 150
}
}
GET /v1/users/123 HTTP/1.1
HTTP/1.1 404 Not Found
{
"type": "https://api.example.com/errors/resource-not-found",
"title": "Resource Not Found",
"detail": "The requested user does not exist",
"status": 404,
"instance": "/v1/users/123"
}
GET /v1/users/123/orders?limit=10&offset=0 HTTP/1.1
1---2name: api-design-rest3description: When creating or extending an HTTP API for client consumption.4license: MIT5---67# RESTful API Design89## Purpose10REST APIs MUST be intuitive, predictable, and semantically correct. This skill ensures APIs use HTTP methods correctly, communicate errors clearly via standard formats, and maintain consistency across resources so clients can interact with them reliably without surprise behavior.1112## When to use13- Building a new backend service exposing resources14- Adding a new domain entity to an existing API15- Creating integration endpoints for third-party partners16- Designing webhooks or callback mechanisms17- Standardizing an inconsistent API across a microservices architecture1819## When NOT to use20- Error handling specifics (use Error Handling Architecture skill)21- API authentication/authorization (separate concern)22- Rate limiting or throttling strategies (separate concern)23- GraphQL design (different paradigm)2425## Inputs required26- Existing API codebase or documented business entities27- HTTP framework (Express, Django, FastAPI, etc.)28- OpenAPI/Swagger familiarity preferred2930## Workflow311. **Identify Resources**: Map business entities to Plural Nouns (users, orders, invoices, not getUsers)322. **Assign Verbs**: Map CRUD operations to HTTP methods: GET (read), POST (create), PUT (replace), PATCH (update), DELETE (remove)333. **Design URL Hierarchy**: Nest resources logically but NO DEEPER than 2 levels (e.g., `/users/{id}/orders` ONLY)344. **Standardize Responses**: All success payloads wrapped consistently; all errors use RFC 7807 format355. **Add Pagination**: For collection endpoints, REQUIRE `limit` and `offset` (or cursor-based pagination)366. **Version the API**: Use `/v1/` prefix or header-based versioning from day one377. **Document with OpenAPI**: Generate OpenAPI schema automatically or maintain it in sync3839## Rules40- MUST use HTTP status codes semantically (see failure conditions below)41- MUST NOT use verbs in URLs (no `GET /getUsers`)42- MUST NOT nest resources beyond 2 levels deep43- MUST use lowercase URLs with hyphens for multi-word resource names44- MUST require API versioning45- MUST return RFC 7807 problem details for ALL errors46- MUST paginate collection responses4748## Anti-patterns49- **Verbs in URLs**: `GET /getUsers`, `POST /createOrder` (use nouns + HTTP methods)50- **HTTP 200 for Errors**: Returning 200 with `{ status: 'error' }` payload (use 4xx/5xx status codes)51- **Deep Nesting**: `/companies/{id}/departments/{id}/employees/{id}/tasks` (use max 2 levels)52- **Mixed Status Codes**: Endpoint returns 200 for success, 200 for validation errors (inconsistent)53- **Unversioned APIs**: Adding `/api/users` without versioning path for future breaking changes5455## Failure conditions56- URLs contain action verbs57- HTTP 200 returned for failed requests58- Resource nesting exceeds 2 levels59- Collection endpoint has no pagination60- Errors not in RFC 7807 format61- API has no versioning strategy6263## Validation checklist64- [ ] All resource URLs are plural nouns (users, orders, not getUsers)65- [ ] HTTP methods used semantically (GET=read, POST=create, PATCH=partial, DELETE=remove)66- [ ] No verbs in URL paths67- [ ] Status codes are correct (201 for create, 204 for delete, 400 for validation, 500 for server errors)68- [ ] All error responses use RFC 7807 format with `type`, `title`, `detail`, `status`69- [ ] Collection endpoints support `limit` and `offset` parameters70- [ ] URLs include version (e.g., `/v1/users` or header-based)71- [ ] URLs use lowercase with hyphens (e.g., `/user-profiles` not `/userProfiles`)72- [ ] Resource nesting does not exceed 2 levels73- [ ] OpenAPI schema is generated or synchronized7475## Output format76- **Response structure**: JSON with consistent key naming (snake_case or camelCase, not mixed)77- **Error format**: RFC 7807 Problem Details (`type`, `title`, `detail`, `status`, `instance`)78- **Pagination**: Include `limit`, `offset`, `total` in collection response envelope79- **Versioning**: `/v1/` URL prefix or `API-Version: 1.0` header80- **Documentation**: OpenAPI 3.0+ schema8182## Security considerations83- Pagination defaults MUST have max limits (prevent DOS via `limit=999999999`)84- Error messages MUST NOT leak internal implementation details85- Resource IDs should not expose sequential patterns (use UUIDs, not auto-increment)86- API MUST enforce authentication/authorization (separate skill)87- Rate limiting MUST be enforced (separate skill)8889## Agent execution notes90- Agent MAY: Create new endpoints, design resource hierarchies, add pagination, generate OpenAPI schema91- Agent MUST NEVER: Use verbs in URLs, return 200 for errors, nest beyond 2 levels, mix status code semantics92- Agent MUST ASK: Before changing versioning strategy, before modifying existing endpoint contracts93- Agent MUST VALIDATE: All status codes correct, no URL verbs, pagination present, RFC 7807 errors9495## Example9697**❌ Anti-pattern (Verbs in URL, wrong status codes, deep nesting, no pagination):**98```http99GET /api/getUsers HTTP/1.1100101HTTP/1.1 200 OK102{103 "status": "error",104 "message": "User not found"105}106107GET /api/companies/123/departments/456/employees/789/tasks/assignToUser HTTP/1.1108```109110**✅ Correct pattern (Nouns, semantic status, proper nesting, paginated):**111```http112GET /v1/users?limit=20&offset=0 HTTP/1.1113114HTTP/1.1 200 OK115{116 "data": [...],117 "pagination": {118 "limit": 20,119 "offset": 0,120 "total": 150121 }122}123124GET /v1/users/123 HTTP/1.1125126HTTP/1.1 404 Not Found127{128 "type": "https://api.example.com/errors/resource-not-found",129 "title": "Resource Not Found",130 "detail": "The requested user does not exist",131 "status": 404,132 "instance": "/v1/users/123"133}134135GET /v1/users/123/orders?limit=10&offset=0 HTTP/1.1136```
Run npx skillmds@latest add kraitdev/api-design-rest in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
When creating or extending an HTTP API for client consumption. It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free. This skill is licensed under MIT.
KraitDev (@kraitdev) published this skill. Their other Agent Skills are listed on their SkillMD profile.