ilude/claude-code-config/api-design-patterns
Claude Code and agent skill by ilude/claude-code-config
- community
Checking that the SKILL.md file is still in the repository.
Language-agnostic API design patterns covering REST and GraphQL, including resource naming, HTTP methods, status codes, versioning, pagination, filtering, authentication, error handling, and schema design. Activate when working with APIs, REST endpoints, GraphQL schemas, API documentation, OpenAPI/Swagger, JWT, OAuth2, endpoint design, API versioning, rate limiting, or GraphQL resolvers.
Install
npx vskill@latest install ilude/claude-code-config/api-design-patternsSKILL.md
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
API Design Patterns
Language-agnostic patterns for designing robust, scalable REST and GraphQL APIs. Focus on solving real problems with simple, maintainable solutions.
Auto-activate when: Working with API routes, endpoints, REST design, GraphQL schemas, OpenAPI/Swagger specs, authentication tokens, API documentation, or discussing endpoint design, versioning strategies, or API architecture.
Philosophy
- Simple over clever - Choose straightforward patterns that solve the problem
- Consistency - Apply patterns consistently across endpoints
- Least Astonishment - APIs should do what their names suggest, nothing more (see
~/.claude/skills/least-astonishment/) - Pragmatism - Pick approaches based on actual use cases, not theoretical purity
- No over-engineering - Don't add features or complexity "just in case"
REST API Design
Resource Naming Conventions
Principles:
- Use nouns for resource names, not verbs
- Use lowercase with hyphens for multi-word resources
- Represent relationships hierarchically
- Use plural for collections
Special cases:
- Singular for singleton resources:
/profile,/settings(user-specific, not collections) - Actions as sub-resources:
/users/{id}/activate(when GET/POST semantics don't fit) - Search/filter: Use query parameters, not new endpoints
GET /users?role=admin&status=active- NOT
GET /users/adminsorGET /active-users
HTTP Methods
| Method | Purpose | Idempotent | Safe | Has Body | |
|---|---|---|---|---|---|
| GET | Retrieve resource | Yes | Yes | No | |
| POST | Create new resource | No | No | Yes | |
| PUT | Replace entire resource | Yes | No | Yes | |
| PATCH | Partial update | No | No | Yes | |
| DELETE | Remove resource | Yes | No | No | |
| HEAD | Like GET, no body | Yes | Yes | No | |
| OPTIONS | Describe communication | Yes | Yes | No |
Best practices:
- GET - MUST NOT use for mutations; safe to retry
- POST - Create new or trigger actions; use 201 Created
- PUT - Full replacement; include all fields
- PATCH - Partial update; only changed fields
- DELETE - Use 204 No Content or 200 with body
Avoid: PATCH if API is simple; use PUT instead. Don't mix PUT/PATCH semantics.
HTTP Status Codes
2xx Success:
200 OK- General success (GET, PUT with response body)201 Created- Resource created (POST)204 No Content- Success, no body (DELETE, PATCH with no response)202 Accepted- Request queued, will process asynchronously
3xx Redirection:
301 Moved Permanently- Resource moved (deprecated endpoints)304 Not Modified- Client cache valid (use ETag/If-None-Match)
4xx Client Error:
400 Bad Request- Invalid input (malformed JSON, missing fields)401 Unauthorized- Missing or invalid auth403 Forbidden- Authenticated but no permission404 Not Found- Resource doesn't exist409 Conflict- Concurrent update or constraint violation422 Unprocessable Entity- Semantically invalid (validation errors)429 Too Many Requests- Rate limit exceeded
5xx Server Error:
500 Internal Server Error- Unexpected error503 Service Unavailable- Temporary downtime
Versioning Strategies
Option 1: URL Path (Explicit, Straightforward)
Pros: Clear, cacheable, explicit breaking changes Cons: Multiple code paths, redundancy
Option 2: Header-based (Clean URLs)
Pros: Clean URLs, version handling logic centralized Cons: Less obvious in browser/logs
Option 3: Media Type (Accept header)
Pros: RESTful, content negotiation Cons: Complex, less common
Recommendation: Use URL versioning for major changes. Avoid if possible - design for forward compatibility:
- Add fields without removing old ones
- Make new features optional
- Deprecated endpoints return 410 Gone with migration info
Pagination Patterns
Offset/Limit (Simple, works for small datasets):
Cursor-based (RECOMMENDED for large datasets):
Pros: Efficient queries, works with distributed systems, stable under concurrent writes Cons: Cursor generation logic needed, no random page access
Keyset pagination (Efficient, uses natural ordering):
Use natural sort fields (ID, timestamp) instead of arbitrary cursors.
Recommendation:
- Small fixed datasets: offset/limit
- Large or growing datasets: cursor-based (RECOMMENDED)
- Simple endpoints: keyset pagination
Idempotency Keys
For safe retries on non-idempotent operations (POST, PATCH):
Implementation:
- Client generates unique key per logical operation
- Server stores key + response for configured duration (e.g., 24 hours)
- Duplicate requests return cached response
- Use 409 Conflict if same key with different payload
Conditional Requests
ETags for cache validation:
Optimistic locking for updates:
Async Operations
For long-running operations, use 202 Accepted with job tracking:
Poll for completion:
OpenAPI Documentation
All REST endpoints MUST be documented with OpenAPI specs:
- Include request/response schemas
- Document all status codes
- Provide example values
- Use
$reffor reusable components - Keep spec in sync with implementation (generate or validate in CI)
Filtering, Sorting, Searching
Filtering:
Sorting:
Searching:
Validation:
- Whitelist allowed filter/sort fields
- Escape search queries (SQL injection prevention)
- Limit result count with pagination
Rate Limiting
Headers:
When limit exceeded:
Strategies:
- Token bucket - Smooth bursts, standard
- Leaky bucket - Even distribution
- Fixed window - Simple, vulnerable to boundary abuse
- Sliding window - Balanced complexity/accuracy
Recommendation: Token bucket per user/API key with reasonable defaults (e.g., 1000 req/hour).
Request/Response Patterns
Request Validation
Validate early:
Request validation example:
Validation error response (400/422):
Error Response Format
Consistent error structure:
Or simplified for simple APIs:
Error codes (use consistently):
INVALID_REQUEST- Malformed requestVALIDATION_ERROR- Field validation failedAUTHENTICATION_FAILED- Invalid credentialsINSUFFICIENT_PERMISSIONS- Authorized but lacks permissionRESOURCE_NOT_FOUND- 404RESOURCE_ALREADY_EXISTS- 409 on duplicateINTERNAL_SERVER_ERROR- 500
Success Response Format
Envelope pattern (good for APIs with metadata):
Direct pattern (simpler, common in modern APIs):
Collection response:
Recommendation: Keep responses consistent. Use envelopes if you need pagination/meta at root level. For collections, include pagination separately.
Partial Responses (Optional)
Allow clients to request specific fields:
Reduces bandwidth for large objects. Implement via field selection in queries (GraphQL does this naturally).
Authentication & Authorization
API Key Pattern
Simple, good for service-to-service:
Pros: Simple, easy to debug Cons: Less secure than OAuth2, no scoping
Storage: Use secure vaults, MUST NOT log keys, rotate regularly.
JWT (JSON Web Token)
Flow:
JWT structure: header.payload.signature
Best practices:
- Store secret securely (environment variable, vault)
- Include expiration (
exp) - Use HTTPS only
- Validate signature on every request
- Refresh tokens for long-lived sessions
- Include scopes for fine-grained permissions
OAuth2 (Delegated Authorization)
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/api-design-patterns/SKILL.md
Popularity
- Repository stars
- 7
- 7-day trend score
- 10
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 23 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ilude/claude-code-config/api-design-patterns)