api-design-best-practices
Skill2 starsChanged 3 months agoMITView on GitHub
API Design Best Practices — RESTful APIs, GraphQL, gRPC, WebSocket, versioning, pagination, security, documentation, testing, performance. Use when designing new APIs or reviewing existing API designs.
Files
API Design Best Practices
RESTful API Design
Resource Naming & HTTP Methods
GET /users # List (200)
POST /users # Create (201 + Location header)
GET /users/{id} # Read (200)
PUT /users/{id} # Full replace (200)
PATCH /users/{id} # Partial update (200)
DELETE /users/{id} # Delete (204)Rules: Plural nouns, kebab-case, max 2-3 nesting levels. Use query params for filtering: /orders?status=active&created_at.gte=2025-01-01
Pagination (Cursor-based preferred)
// Request: GET /users?cursor=eyJpZCI6MTAwfQ&limit=20
// Response:
{"data": [...], "next_cursor": "eyJpZCI6MTIwfQ", "has_more": true}Error Response (RFC 7807)
{"type": "https://api.example.com/errors/validation",
"title": "Validation Error",
"status": 422,
"detail": "Email is required",
"errors": {"email": ["is required", "must be valid format"]}}Versioning
URL: /api/v1/users
Accept: application/vnd.myapi.v1+json
Deprecation: true
Sunset: Sat, 31 Dec 2025 23:59:59 GMTGraphQL
Schema First
type Query { user(id: ID!): User @rateLimit(limit: 100, duration: 60) }
type Mutation { createUser(input: CreateUserInput!): User! }
type User @key(fields: "id") {
id: ID!; name: String!; email: String! @deprecated(reason: "Use emailNew")
}N+1 Prevention (DataLoader)
const userLoader = new DataLoader(async (ids) => {
const users = await db.users.findByIds(ids);
return ids.map(id => users.find(u => u.id === id));
});
// Resolver: orders: (parent) => orderLoader.load(parent.id)Security
// Cost analysis
const cost = graphqlCostAnalysis(schema, query, { maxCost: 1000 });
// Depth limiting
validationRules: [depthLimit(5)]
// Query whitelisting (persisted queries)gRPC
service UserService {
rpc GetUser (GetUserRequest) returns (User) {}
rpc ListUsers (ListUsersRequest) returns (stream User) {} // Server streaming
}
message GetUserRequest { string id = 1; }
message User { string id = 1; string name = 2; }API Security
| Security | Implementation |
| Rate Limiting | Token bucket: 100 req/min per IP |
| Auth | OAuth 2.0 (Authorization Code + PKCE) |
| JWT | RS256 signed, 15min expiry, include jti, iss, aud |
| CORS | Whitelist specific origins, not * |
| Input Validation | Zod schemas at every boundary |
| Request Signing | HMAC-SHA256 for webhook payloads |
API Gateway Patterns
# Kong route example
routes:
- paths: ["/api/v1/users"]
methods: ["GET", "POST"]
plugins:
- name: rate-limiting
config: { minute: 100, policy: local }
- name: key-authAPI Testing
// Contract test (Pact)
await provider.addInteraction({
state: 'user exists',
uponReceiving: 'get user by id',
withRequest: { method: 'GET', path: '/users/123' },
willRespondWith: { status: 200, body: { id: '123' } }
});API Design Checklist
- Consistent naming (plural nouns, kebab-case)
- Proper status codes (201 for create, 204 for delete)
- Versioning strategy defined
- Pagination (cursor-based for real-time)
- Error format (RFC 7807)
- Rate limiting headers (X-RateLimit-Remaining)
- Auth (Bearer token / API key)
- CORS configured (not
*) - Request validation at boundary
- Response compression (gzip/brotli)
- Cache headers (ETag, Cache-Control)
- API documentation (OpenAPI 3.1)
In this repository383 other files it gives its agents.
- 37signals-waySkill
- ab-test-analysisSkill
- advisor-orchestrator-workerSkill
- ai-ml-engineeringSkill
- algorithmic-artSkill
- analyze-feature-requestsSkill
- animation-vocabularySkill
- apple-designSkill
- emil-design-engSkill
- find-animation-opportunitiesSkill
- improve-animationsSkill
- pick-ui-librarySkill
- prototypeSkill
- review-animationsSkill
- ansoff-matrixSkill
- api-and-interface-designSkill
- app-store-changelogSkill
- auth-authorizationSkill
- beachhead-segmentSkill
- blue-ocean-strategySkill
- brainstorm-experiments-existingSkill
- brainstorm-experiments-newSkill
- brainstorm-ideas-existingSkill
- brainstorm-ideas-newSkill
- brainstorm-okrsSkill
- brand-guidelinesSkill
- browser-testing-with-devtoolsSkill
- bug-hunt-swarmSkill
- business-modelSkill
- canvas-designSkill
- ci-cd-and-automationSkill
- claude-apiSkill
- clean-architectureSkill
- clean-codeSkill
- cli-creatorSkill
- code-review-and-qualitySkill
- code-review-skillSkill
- code-simplificationSkill
- cohort-analysisSkill
- cold-start-problemSkill
- commit-archaeologistSkill
- competitive-battlecardSkill
- competitor-analysisSkill
- contagiousSkill
- context-engineeringSkill
- continuous-discoverySkill
- architecture-blueprint-generatorSkill
- azure-architecture-autopilotSkill
- cli-masterySkill
- codeqlSkill
- conventional-commitSkill
- create-implementation-planSkill
- csharp-asyncSkill
- diagnoseSkill
- dotnet-best-practicesSkill
- draw-io-diagram-generatorSkill
- git-commitSkill
- github-actions-efficiencySkill
- java-springbootSkill
- mcp-cliSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

