Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Design RESTful and GraphQL APIs following industry best practices for consistency, versioning, and developer experience.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: api-design-principles3description: Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.4---56# API Design Principles78Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers and stand the test of time.910## When to Use This Skill1112- Designing new REST or GraphQL APIs13- Refactoring existing APIs for better usability14- Establishing API design standards for your team15- Reviewing API specifications before implementation16- Migrating between API paradigms (REST to GraphQL, etc.)17- Creating developer-friendly API documentation18- Optimizing APIs for specific use cases (mobile, third-party integrations)1920## Core Concepts2122### 1. RESTful Design Principles2324**Resource-Oriented Architecture**2526- Resources are nouns (users, orders, products), not verbs27- Use HTTP methods for actions (GET, POST, PUT, PATCH, DELETE)28- URLs represent resource hierarchies29- Consistent naming conventions3031**HTTP Methods Semantics:**3233- `GET`: Retrieve resources (idempotent, safe)34- `POST`: Create new resources35- `PUT`: Replace entire resource (idempotent)36- `PATCH`: Partial resource updates37- `DELETE`: Remove resources (idempotent)3839### 2. GraphQL Design Principles4041**Schema-First Development**4243- Types define your domain model44- Queries for reading data45- Mutations for modifying data46- Subscriptions for real-time updates4748**Query Structure:**4950- Clients request exactly what they need51- Single endpoint, multiple operations52- Strongly typed schema53- Introspection built-in5455### 3. API Versioning Strategies5657**URL Versioning:**5859```60/api/v1/users61/api/v2/users62```6364**Header Versioning:**6566```67Accept: application/vnd.api+json; version=168```6970**Query Parameter Versioning:**7172```73/api/users?version=174```7576## Detailed patterns and worked examples7778Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.7980## Best Practices8182### REST APIs83841. **Consistent Naming**: Use plural nouns for collections (`/users`, not `/user`)852. **Stateless**: Each request contains all necessary information863. **Use HTTP Status Codes Correctly**: 2xx success, 4xx client errors, 5xx server errors874. **Version Your API**: Plan for breaking changes from day one885. **Pagination**: Always paginate large collections896. **Rate Limiting**: Protect your API with rate limits907. **Documentation**: Use OpenAPI/Swagger for interactive docs9192### GraphQL APIs93941. **Schema First**: Design schema before writing resolvers952. **Avoid N+1**: Use DataLoaders for efficient data fetching963. **Input Validation**: Validate at schema and resolver levels974. **Error Handling**: Return structured errors in mutation payloads985. **Pagination**: Use cursor-based pagination (Relay spec)996. **Deprecation**: Use `@deprecated` directive for gradual migration1007. **Monitoring**: Track query complexity and execution time101102## Common Pitfalls103104- **Over-fetching/Under-fetching (REST)**: Fixed in GraphQL but requires DataLoaders105- **Breaking Changes**: Version APIs or use deprecation strategies106- **Inconsistent Error Formats**: Standardize error responses107- **Missing Rate Limits**: APIs without limits are vulnerable to abuse108- **Poor Documentation**: Undocumented APIs frustrate developers109- **Ignoring HTTP Semantics**: POST for idempotent operations breaks expectations110- **Tight Coupling**: API structure shouldn't mirror database schema111