Designing apis skill
Designs REST and GraphQL APIs including endpoints, error handling, versioning, and documentation.
by CloudAI-X·MIT license·★ 1,416 Stars on the repo·GitHub ↗
Use now
npx degit CloudAI-X/claude-workflow-v2/skills/designing-apis#main ~/.claude/skills/designing-apisChecked ·commit main
Files of Designing apis
SKILL.md
Show the full text230 lines
Designing APIs
When to Load
- Trigger: Designing REST or GraphQL endpoints, API contracts, versioning, request/response formats
- Skip: Internal-only code with no API surface
API Design Workflow
Copy this checklist and track progress:
API Design Progress:
- [ ] Step 1: Define resources and relationships
- [ ] Step 2: Design endpoint structure
- [ ] Step 3: Define request/response formats
- [ ] Step 4: Plan error handling
- [ ] Step 5: Add authentication/authorization
- [ ] Step 6: Document with OpenAPI spec
- [ ] Step 7: Validate design against checklist
REST API Design
URL Structure
# Resource-based URLs (nouns, not verbs)
GET /users # List users
GET /users/:id # Get user
POST /users # Create user
PUT /users/:id # Replace user
PATCH /users/:id # Update user
DELETE /users/:id # Delete user
# Nested resources
GET /users/:id/orders # User's orders
POST /users/:id/orders # Create order for user
# Query parameters for filtering/pagination
GET /users?role=admin&status=active
GET /users?page=2&limit=20&sort=-createdAt
HTTP Status Codes
| Code | Meaning | Use Case |
|---|---|---|
| 200 | OK | Successful GET, PUT, PATCH |
| 201 | Created | Successful POST |
| 204 | No Content | Successful DELETE |
| 400 | Bad Request | Invalid input |
| 401 | Unauthorized | Missing/invalid auth |
| 403 | Forbidden | Valid auth, no permission |
| 404 | Not Found | Resource doesn't exist |
| 409 | Conflict | Duplicate, state conflict |
| 422 | Unprocessable | Validation failed |
| 429 | Too Many Requests | Rate limited |
| 500 | Internal Error | Server error |
Response Formats
Success Response:
{
"data": {
"id": "123",
"type": "user",
"attributes": {
"name": "John Doe",
"email": "[email protected]"
}
},
"meta": {
"requestId": "abc-123"
}
}
List Response with Pagination:
{
"data": [...],
"meta": {
"total": 100,
"page": 1,
"limit": 20,
"totalPages": 5
},
"links": {
"self": "/users?page=1",
"next": "/users?page=2",
"last": "/users?page=5"
}
}
Error Response:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data",
"details": [
{
"field": "email",
"message": "Must be a valid email address"
}
]
},
"meta": {
"requestId": "abc-123"
}
}
API Versioning
URL Versioning (Recommended):
/api/v1/users
/api/v2/users
Header Versioning:
Accept: application/vnd.example.v1+json
Authentication Patterns
JWT Bearer Token:
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
API Key:
X-API-Key: your-api-key
Rate Limiting Headers
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1609459200
Retry-After: 60
GraphQL Patterns
Schema Design:
# Abbreviated: input, connection and error types omitted for brevity
type Query {
user(id: ID!): User
users(filter: UserFilter, pagination: Pagination): UserConnection!
}
type Mutation {
createUser(input: CreateUserInput!): UserPayload!
updateUser(id: ID!, input: UpdateUserInput!): UserPayload!
}
type User {
id: ID!
name: String!
email: String!
orders(first: Int, after: String): OrderConnection!
}
input CreateUserInput {
name: String!
email: String!
}
type UserPayload {
user: User
errors: [Error!]
}
OpenAPI Specification Template
See OPENAPI-TEMPLATE.md for the full OpenAPI 3.0 specification template.
API Design Validation
After completing the design, validate against this checklist:
Validation Checklist:
- [ ] All endpoints use nouns, not verbs
- [ ] HTTP methods match operations correctly
- [ ] Consistent response format across endpoints
- [ ] Error responses include actionable details
- [ ] Pagination implemented for list endpoints
- [ ] Authentication defined for protected endpoints
- [ ] Rate limiting headers documented
- [ ] OpenAPI spec is complete and valid
If validation fails, return to the relevant design step and address the issues.
Security Checklist
- HTTPS only
- Authentication on all endpoints
- Authorization checks
- Input validation
- Rate limiting
- Request size limits
- CORS properly configured
- No sensitive data in URLs
- Audit logging
| 1 | |
| 2 | name designing-apis |
| 3 | description Designs REST and GraphQL APIs including endpoints, error handling, versioning, and documentation. Use when creating new APIs, designing endpoints, reviewing API contracts, or when asked about REST, GraphQL, or API patterns. |
| 4 | |
| 5 | |
| 6 | # Designing APIs |
| 7 | |
| 8 | ### When to Load |
| 9 | |
| 10 | **Trigger**: Designing REST or GraphQL endpoints, API contracts, versioning, request/response formats |
| 11 | **Skip**: Internal-only code with no API surface |
| 12 | |
| 13 | ## API Design Workflow |
| 14 | |
| 15 | Copy this checklist and track progress: |
| 16 | |
| 17 | |
| 18 | API Design Progress: |
| 19 | - [ ] Step 1: Define resources and relationships |
| 20 | - [ ] Step 2: Design endpoint structure |
| 21 | - [ ] Step 3: Define request/response formats |
| 22 | - [ ] Step 4: Plan error handling |
| 23 | - [ ] Step 5: Add authentication/authorization |
| 24 | - [ ] Step 6: Document with OpenAPI spec |
| 25 | - [ ] Step 7: Validate design against checklist |
| 26 | |
| 27 | |
| 28 | ## REST API Design |
| 29 | |
| 30 | ### URL Structure |
| 31 | |
| 32 | |
| 33 | # Resource-based URLs (nouns, not verbs) |
| 34 | GET /users # List users |
| 35 | GET /users/:id # Get user |
| 36 | POST /users # Create user |
| 37 | PUT /users/:id # Replace user |
| 38 | PATCH /users/:id # Update user |
| 39 | DELETE /users/:id # Delete user |
| 40 | |
| 41 | # Nested resources |
| 42 | GET /users/:id/orders # User's orders |
| 43 | POST /users/:id/orders # Create order for user |
| 44 | |
| 45 | # Query parameters for filtering/pagination |
| 46 | GET /users?role=admin&status=active |
| 47 | GET /users?page=2&limit=20&sort=-createdAt |
| 48 | |
| 49 | |
| 50 | ### HTTP Status Codes |
| 51 | |
| 52 | | Code | Meaning | Use Case | |
| 53 | | ---- | ----------------- | -------------------------- | |
| 54 | | 200 | OK | Successful GET, PUT, PATCH | |
| 55 | | 201 | Created | Successful POST | |
| 56 | | 204 | No Content | Successful DELETE | |
| 57 | | 400 | Bad Request | Invalid input | |
| 58 | | 401 | Unauthorized | Missing/invalid auth | |
| 59 | | 403 | Forbidden | Valid auth, no permission | |
| 60 | | 404 | Not Found | Resource doesn't exist | |
| 61 | | 409 | Conflict | Duplicate, state conflict | |
| 62 | | 422 | Unprocessable | Validation failed | |
| 63 | | 429 | Too Many Requests | Rate limited | |
| 64 | | 500 | Internal Error | Server error | |
| 65 | |
| 66 | ### Response Formats |
| 67 | |
| 68 | **Success Response:** |
| 69 | |
| 70 | |
| 71 | { |
| 72 | "data": { |
| 73 | "id": "123", |
| 74 | "type": "user", |
| 75 | "attributes": { |
| 76 | "name": "John Doe", |
| 77 | "email": "[email protected]" |
| 78 | } |
| 79 | }, |
| 80 | "meta": { |
| 81 | "requestId": "abc-123" |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | **List Response with Pagination:** |
| 87 | |
| 88 | |
| 89 | { |
| 90 | "data": [...], |
| 91 | "meta": { |
| 92 | "total": 100, |
| 93 | "page": 1, |
| 94 | "limit": 20, |
| 95 | "totalPages": 5 |
| 96 | }, |
| 97 | "links": { |
| 98 | "self": "/users?page=1", |
| 99 | "next": "/users?page=2", |
| 100 | "last": "/users?page=5" |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | **Error Response:** |
| 106 | |
| 107 | |
| 108 | { |
| 109 | "error": { |
| 110 | "code": "VALIDATION_ERROR", |
| 111 | "message": "Invalid input data", |
| 112 | "details": [ |
| 113 | { |
| 114 | "field": "email", |
| 115 | "message": "Must be a valid email address" |
| 116 | } |
| 117 | ] |
| 118 | }, |
| 119 | "meta": { |
| 120 | "requestId": "abc-123" |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | |
| 125 | ## API Versioning |
| 126 | |
| 127 | **URL Versioning (Recommended):** |
| 128 | |
| 129 | |
| 130 | /api/v1/users |
| 131 | /api/v2/users |
| 132 | |
| 133 | |
| 134 | **Header Versioning:** |
| 135 | |
| 136 | |
| 137 | Accept: application/vnd.example.v1+json |
| 138 | |
| 139 | |
| 140 | ## Authentication Patterns |
| 141 | |
| 142 | **JWT Bearer Token:** |
| 143 | |
| 144 | |
| 145 | Authorization: Bearer eyJhbGciOiJIUzI1NiIs... |
| 146 | |
| 147 | |
| 148 | **API Key:** |
| 149 | |
| 150 | |
| 151 | X-API-Key: your-api-key |
| 152 | |
| 153 | |
| 154 | ## Rate Limiting Headers |
| 155 | |
| 156 | |
| 157 | X-RateLimit-Limit: 100 |
| 158 | X-RateLimit-Remaining: 95 |
| 159 | X-RateLimit-Reset: 1609459200 |
| 160 | Retry-After: 60 |
| 161 | |
| 162 | |
| 163 | ## GraphQL Patterns |
| 164 | |
| 165 | **Schema Design:** |
| 166 | |
| 167 | |
| 168 | # Abbreviated: input, connection and error types omitted for brevity |
| 169 | type Query { |
| 170 | user(id: ID!): User |
| 171 | users(filter: UserFilter, pagination: Pagination): UserConnection! |
| 172 | } |
| 173 | |
| 174 | type Mutation { |
| 175 | createUser(input: CreateUserInput!): UserPayload! |
| 176 | updateUser(id: ID!, input: UpdateUserInput!): UserPayload! |
| 177 | } |
| 178 | |
| 179 | type User { |
| 180 | id: ID! |
| 181 | name: String! |
| 182 | email: String! |
| 183 | orders(first: Int, after: String): OrderConnection! |
| 184 | } |
| 185 | |
| 186 | input CreateUserInput { |
| 187 | name: String! |
| 188 | email: String! |
| 189 | } |
| 190 | |
| 191 | type UserPayload { |
| 192 | user: User |
| 193 | errors: [Error!] |
| 194 | } |
| 195 | |
| 196 | |
| 197 | ## OpenAPI Specification Template |
| 198 | |
| 199 | See [OPENAPI-TEMPLATE.md] for the full OpenAPI 3.0 specification template. |
| 200 | |
| 201 | ## API Design Validation |
| 202 | |
| 203 | After completing the design, validate against this checklist: |
| 204 | |
| 205 | |
| 206 | Validation Checklist: |
| 207 | - [ ] All endpoints use nouns, not verbs |
| 208 | - [ ] HTTP methods match operations correctly |
| 209 | - [ ] Consistent response format across endpoints |
| 210 | - [ ] Error responses include actionable details |
| 211 | - [ ] Pagination implemented for list endpoints |
| 212 | - [ ] Authentication defined for protected endpoints |
| 213 | - [ ] Rate limiting headers documented |
| 214 | - [ ] OpenAPI spec is complete and valid |
| 215 | |
| 216 | |
| 217 | If validation fails, return to the relevant design step and address the issues. |
| 218 | |
| 219 | ## Security Checklist |
| 220 | |
| 221 | [ ] HTTPS only |
| 222 | [ ] Authentication on all endpoints |
| 223 | [ ] Authorization checks |
| 224 | [ ] Input validation |
| 225 | [ ] Rate limiting |
| 226 | [ ] Request size limits |
| 227 | [ ] CORS properly configured |
| 228 | [ ] No sensitive data in URLs |
| 229 | [ ] Audit logging |
| 230 |
Discussion
Alternatives
Browse more free Claude skills or everything in Development.