api-design-patterns — Claude Code skill: REST API rules
A skill with 38 REST API rules covering resources, errors, security, pagination and versioning. Useful when an agent writes or reviews endpoints.
npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a claude-codeWhat api-design-patterns does
The skill splits into 7 categories by priority. The critical ones are resource design (rest-), error handling (error-) and security (sec-). Pagination and filtering, versioning, response format and documentation follow. Each rule has its own prefix and its own file under rules/, such as rules/rest-http-methods.md or rules/error-consistent-format.md.
Sample payloads ship with it: an error response shape, a pagination block with meta and links, and X-RateLimit-* headers. The agent leans on those when it proposes an endpoint layout. Everything is compiled into AGENTS.md.
The skill does not scan your code on its own. It gives the agent a frame to reason inside. If your project already returns a different envelope or versions through a header, the URL-path and response-envelope rules will fight that choice. Tell the agent which approach wins.
What it helps with
- design endpoints with nouns in the URL instead of verbs
- settle on one error shape with a machine-readable code
- pick cursor or offset pagination for a given dataset
- plan a versioning and deprecation path for endpoints
- audit an existing API for gaps in auth and input validation
Example prompts for the agent
- design a REST API for orders using api-design-patterns
- review my endpoints against REST best practices
- give every handler the same error format with a request_id
How to install api-design-patterns
1Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a claude-code2Manually: put the files in place
~/.claude/skills/api-design-patterns/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/api-design-patterns/
1Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a codex2Manually: put the files in place
.agents/skills/api-design-patterns/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a cursor2Manually: put the files in place
.cursor/skills/api-design-patterns/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install AsyrafHussin/agent-skills api-design-patterns2Manually: put the files in place
.github/skills/api-design-patterns/SKILL.md1Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a gemini-cli2Platform CLI
gemini skills install https://github.com/AsyrafHussin/agent-skills --path skills/api-design-patternsManually: put the files in place
.devin/skills/api-design-patterns/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about api-design-patterns
How do I install api-design-patterns in Claude?
Run npx skills add AsyrafHussin/agent-skills --skill api-design-patterns -a claude-code. The skill file then lands at ~/.claude/skills/api-design-patterns/SKILL.md.
What does api-design-patterns do?
It hands the agent a rule set for REST: resource naming, HTTP methods, status codes, error format, pagination, versioning, security and docs. That is 38 rules across 7 categories.
Does the skill force URL-based versioning?
It includes ver-url-path for a version in the path like /api/v1/, and ver-header-based for versioning through the Accept header. You pick which one applies.
Source text
SKILL.md · MIT
---
name: api-design-patterns
description: RESTful API design, error handling, versioning, and best practices. Use when designing APIs, reviewing endpoints, implementing error responses, or setting up API structure. Triggers on "design API", "review API", "REST best practices", or "API patterns".
license: MIT
metadata:
author: agent-skills
version: "2.0.0"
---
# API Design Patterns
RESTful API design principles for building consistent, developer-friendly APIs. Contains 38 rules across 7 categories covering resource design, error handling, security, pagination, versioning, response format, and documentation.
## Metadata
- **Version:** 2.0.0
- **Rule Count:** 38 rules across 7 categories
- **License:** MIT
## When to Apply
Reference these guidelines when:
- Designing new API endpoints
- Reviewing existing API structure
- Implementing error handling and validation
- Setting up pagination, filtering, and sorting
- Planning API versioning strategy
- Configuring API security (auth, CORS, rate limiting)
- Writing API documentation (OpenAPI/Swagger)
## Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Resource Design | CRITICAL | `rest-` |
| 2 | Error Handling | CRITICAL | `error-` |
| 3 | Security | CRITICAL | `sec-` |
| 4 | Pagination & Filtering | HIGH | `page-`, `filter-`, `sort-` |
| 5 | Versioning | HIGH | `ver-` |
| 6 | Response Format | MEDIUM | `resp-` |
| 7 | Documentation | MEDIUM | `doc-` |
## Quick Reference
### 1. Resource Design (CRITICAL)
- `rest-nouns-not-verbs` - Use nouns for endpoints, not verbs
- `rest-plural-resources` - Use plural resource names
- `rest-http-methods` - Correct HTTP method usage (GET, POST, PUT, PATCH, DELETE)
- `rest-nested-resources` - Proper resource nesting (max 2 levels)
- `rest-status-codes` - Appropriate HTTP status codes
- `rest-idempotency` - Idempotent operations with idempotency keys
- `rest-hateoas` - Hypermedia links for discoverability
- `rest-resource-actions` - Non-CRUD actions as sub-resources
### 2. Error Handling (CRITICAL)
- `error-consistent-format` - Consistent error response structure
- `error-meaningful-messages` - Helpful, actionable error messages
- `error-validation-details` - Field-level validation errors
- `error-error-codes` - Machine-readable error codes
- `error-no-stack-traces` - Never expose stack traces in production
- `error-request-id` - Include request IDs for debugging
### 3. Security (CRITICAL)
- `sec-authentication` - Proper auth implementation (OAuth2/JWT)
- `sec-authorization` - Resource-level permissions (RBAC)
- `sec-rate-limiting` - Prevent abuse with rate limiting
- `sec-input-validation` - Validate and sanitize all input
- `sec-cors-config` - CORS configuration with whitelists
- `sec-https-only` - Enforce HTTPS for all traffic
- `sec-sensitive-data` - Protect passwords, tokens, PII
### 4. Pagination & Filtering (HIGH)
- `page-cursor-based` - Cursor pagination for large datasets
- `page-offset-based` - Offset pagination for simple cases
- `page-consistent-params` - Consistent parameter naming
- `page-metadata` - Include pagination metadata in responses
- `filter-query-params` - Filter via query parameters
- `sort-flexible` - Flexible sorting with `-` prefix for descending
### 5. Versioning (HIGH)
- `ver-url-path` - Version in URL path (/api/v1/)
- `ver-header-based` - Version via Accept header
- `ver-backward-compatible` - Maintain backward compatibility
- `ver-deprecation` - Deprecation strategy with Sunset header
### 6. Response Format (MEDIUM)
- `resp-consistent-structure` - Consistent response envelope
- `resp-json-conventions` - JSON naming conventions
- `resp-partial-responses` - Field selection (sparse fieldsets)
- `resp-compression` - Response compression (gzip/Brotli)
### 7. Documentation (MEDIUM)
- `doc-openapi` - OpenAPI/Swagger specification
- `doc-examples` - Request/response examples
- `doc-changelog` - API changelog
## Essential Guidelines
### Resource Naming
```
# ❌ Verbs in URLs
GET /getUsers
POST /createUser
# ✅ Nouns with HTTP methods
GET /users # List users
POST /users # Create user
GET /users/123 # Get user
PUT /users/123 # Update user (full)
PATCH /users/123 # Update user (partial)
DELETE /users/123 # Delete user
```
### Error Response Format
```json
{
"error": {
"code": "VALIDATION_ERROR",
"message": "The request contains invalid data",
"details": [
{
"field": "email",
"code": "INVALID_FORMAT",
"message": "Please provide a valid email address"
}
],
"request_id": "req_abc123"
}
}
```
### Pagination
```json
{
"data": [...],
"meta": {
"current_page": 2,
"per_page": 20,
"total_pages": 10,
"total_count": 195
},
"links": {
"first": "/users?page=1&per_page=20",
"prev": "/users?page=1&per_page=20",
"next": "/users?page=3&per_page=20",
"last": "/users?page=10&per_page=20"
}
}
```
### Rate Limiting Headers
```
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 998
X-RateLimit-Reset: 1640995200
```
## How to Use
Read individual rule files for detailed explanations:
```
rules/rest-http-methods.md
rules/error-consistent-format.md
rules/page-cursor-based.md
rules/sec-authentication.md
rules/ver-url-path.md
rules/doc-openapi.md
```
## References
- [RESTful API Guidelines](https://restfulapi.net)
- [Zalando RESTful API Guidelines](https://zalando.github.io/restful-api-guidelines)
- [Microsoft API Guidelines](https://github.com/microsoft/api-guidelines)
- [Google API Design Guide](https://cloud.google.com/apis/design)
- [OpenAPI Specification](https://swagger.io/specification)
## Full Compiled Document
For the complete guide with all rules expanded: `AGENTS.md`
© agent-skills · MIT · AsyrafHussin/agent-skills