API Design
Comprehensive API design patterns covering REST/GraphQL framework design, versioning strategies, and RFC 9457 error handling. Each category has individual rule files in rules/ loaded on-demand.
Quick Reference
| Category |
Rules |
Impact |
When to Use |
| API Framework |
3 |
HIGH |
REST conventions, resource modeling, OpenAPI specifications |
| Versioning |
3 |
HIGH |
URL path versioning, header versioning, deprecation/sunset policies |
| Error Handling |
4 |
HIGH |
RFC 9457 Problem Details, agent-facing errors, validation errors, error type registries |
| GraphQL |
2 |
HIGH |
Strawberry code-first, DataLoader, permissions, subscriptions |
| gRPC |
2 |
HIGH |
Protobuf services, streaming, interceptors, retry |
| Streaming |
2 |
HIGH |
SSE endpoints, WebSocket bidirectional, async generators |
| Integrations | 2 | HIGH | Messaging platforms (WhatsApp, Telegram), Payload CMS patterns |
Total: 18 rules across 7 categories
API Framework
REST and GraphQL API design conventions for consistent, developer-friendly APIs.
| Rule |
File |
Key Pattern |
| REST Conventions |
rules/framework-rest-conventions.md |
Plural nouns, HTTP methods, status codes, pagination |
| Resource Modeling |
rules/framework-resource-modeling.md |
Hierarchical URLs, filtering, sorting, field selection |
| OpenAPI |
rules/framework-openapi.md |
OpenAPI 3.1 specs, documentation, schema definitions |
Versioning
Strategies for API evolution without breaking clients.
| Rule |
File |
Key Pattern |
| URL Path |
rules/versioning-url-path.md |
/api/v1/ prefix routing, version-specific schemas |
| Header |
rules/versioning-header.md |
X-API-Version header, content negotiation |
| Deprecation |
rules/versioning-deprecation.md |
Sunset headers, lifecycle management, breaking change policy |
Error Handling
RFC 9457 Problem Details for machine-readable, standardized error responses.
| Rule |
File |
Key Pattern |
| Problem Details |
rules/errors-problem-details.md |
RFC 9457 schema, application/problem+json, exception classes |
| Agent-Facing Errors |
rules/errors-agent-facing.md |
Agent extensions: retryable, error_category, content negotiation, token efficiency |
| Validation |
rules/errors-validation.md |
Field-level errors, Pydantic integration, 422 responses |
| Error Catalog |
rules/errors-error-catalog.md |
Problem type registry, error type URIs, client handling |
GraphQL
Strawberry GraphQL code-first schema with type-safe resolvers and FastAPI integration.
| Rule |
File |
Key Pattern |
| Schema Design |
rules/graphql-strawberry.md |
Type-safe schema, DataLoader, union errors, Private fields |
| Patterns & Auth |
rules/graphql-schema.md |
Permission classes, FastAPI integration, subscriptions |
gRPC
High-performance gRPC for internal microservice communication.
| Rule |
File |
Key Pattern |
| Service Definition |
rules/grpc-service.md |
Protobuf, async server, client timeout, code generation |
| Streaming & Interceptors |
rules/grpc-streaming.md |
Server/bidirectional streaming, auth, retry backoff |
Streaming
Real-time data streaming with SSE, WebSockets, and proper cleanup.
| Rule |
File |
Key Pattern |
| SSE |
rules/streaming-sse.md |
SSE endpoints, LLM streaming, reconnection, keepalive |
| WebSocket |
rules/streaming-websocket.md |
Bidirectional, heartbeat, aclosing(), backpressure |
Integrations
Messaging platform integrations and headless CMS patterns.
| Rule |
File |
Key Pattern |
| Messaging Platforms |
rules/messaging-integrations.md |
WhatsApp WAHA, Telegram Bot API, webhook security |
| Payload CMS |
rules/payload-cms.md |
Payload 3.0 collections, access control, CMS selection |
Quick Start Example
# REST endpoint with versioning and RFC 9457 errors
from fastapi import APIRouter, Depends, Request
from fastapi.responses import JSONResponse
router = APIRouter()
@router.get("/api/v1/users/{user_id}")
async def get_user(user_id: str, service: UserService = Depends()):
user = await service.get_user(user_id)
if not user:
raise NotFoundProblem(
resource="User",
resource_id=user_id,
)
return UserResponseV1(id=user.id, name=user.full_name)
Key Decisions
| Decision |
Recommendation |
| Versioning strategy |
URL path (/api/v1/) for public APIs |
| Resource naming |
Plural nouns, kebab-case |
| Pagination |
Cursor-based for large datasets |
| Error format |
RFC 9457 Problem Details with application/problem+json |
| Error type URI |
Your API domain + /problems/ prefix |
| Support window |
Current + 1 previous version |
| Deprecation notice |
3 months minimum before sunset |
| Sunset period |
6 months after deprecation |
| GraphQL schema |
Code-first with Strawberry types |
| N+1 prevention |
DataLoader for all nested resolvers |
| GraphQL auth |
Permission classes (context-based) |
| gRPC proto |
One service per file, shared common.proto |
| gRPC streaming |
Server stream for lists, bidirectional for real-time |
| SSE keepalive |
Every 30 seconds |
| WebSocket heartbeat |
ping-pong every 30 seconds |
| Async generator cleanup |
aclosing() for all external resources |
Common Mistakes
- Verbs in URLs (
POST /createUser instead of POST /users)
- Inconsistent error formats across endpoints
- Breaking contracts without version bump
- Plain text error responses instead of Problem Details
- Sunsetting versions without deprecation headers
- Exposing internal details (stack traces, DB errors) in errors
- Missing
Content-Type: application/problem+json on error responses
- Supporting too many concurrent API versions (max 2-3)
- Caching without considering version isolation
Evaluations
See test-cases.json for 9 test cases across all categories.
Related Skills
fastapi-advanced - FastAPI-specific implementation patterns
rate-limiting - Advanced rate limiting implementations and algorithms
observability-monitoring - Version usage metrics and error tracking
input-validation - Validation patterns beyond API error handling
streaming-api-patterns - SSE and WebSocket patterns for real-time APIs
Capability Details
rest-design
Keywords: rest, restful, http, endpoint, route, path, resource, CRUD
Solves:
- How do I design RESTful APIs?
- REST endpoint patterns and conventions
- HTTP methods and status codes
graphql-design
Keywords: graphql, schema, query, mutation, connection, relay
Solves:
- How do I design GraphQL APIs?
- Schema design best practices
- Connection pattern for pagination
endpoint-design
Keywords: endpoint, route, path, resource, CRUD, openapi
Solves:
- How do I structure API endpoints?
- What's the best URL pattern for this resource?
- RESTful endpoint naming conventions
url-versioning
Keywords: url version, path version, /v1/, /v2/
Solves:
- How to version REST APIs?
- URL-based API versioning
header-versioning
Keywords: header version, X-API-Version, content negotiation
Solves:
- Clean URL versioning
- Header-based API version
deprecation
Keywords: deprecation, sunset, version lifecycle, backward compatible
Solves:
- How to deprecate API versions?
- Version sunset policy
- Breaking vs non-breaking changes
problem-details
Keywords: problem details, RFC 9457, RFC 7807, structured error, application/problem+json
Solves:
- How to standardize API error responses?
- What format for API errors?
agent-facing-errors
Keywords: agent error, AI agent, retryable, retry_after, error_category, content negotiation, accept header, token efficient, machine readable
Solves:
- How to design error responses for AI agent consumers?
- How to reduce token cost of error responses?
- How to enable deterministic agent error handling?
- Content negotiation for agents vs browsers vs LLMs
validation-errors
Keywords: validation, field error, 422, unprocessable, pydantic
Solves:
- How to handle validation errors in APIs?
- Field-level error responses
error-registry
Keywords: error registry, problem types, error catalog, error codes
Solves:
- How to document all API errors?
- Error type management
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: api-design-213description: API design patterns for REST/GraphQL framework design, versioning strategies, and RFC 9457 error handling. Use when designing API endpoints, choosing versioning schemes, implementing Problem Details errors, or building OpenAPI specifications. Use when this capability is needed.4---56# API Design78Comprehensive API design patterns covering REST/GraphQL framework design, versioning strategies, and RFC 9457 error handling. Each category has individual rule files in `rules/` loaded on-demand.910## Quick Reference1112| Category | Rules | Impact | When to Use |13|----------|-------|--------|-------------|14| [API Framework](#api-framework) | 3 | HIGH | REST conventions, resource modeling, OpenAPI specifications |15| [Versioning](#versioning) | 3 | HIGH | URL path versioning, header versioning, deprecation/sunset policies |16| [Error Handling](#error-handling) | 4 | HIGH | RFC 9457 Problem Details, agent-facing errors, validation errors, error type registries |17| [GraphQL](#graphql) | 2 | HIGH | Strawberry code-first, DataLoader, permissions, subscriptions |18| [gRPC](#grpc) | 2 | HIGH | Protobuf services, streaming, interceptors, retry |19| [Streaming](#streaming) | 2 | HIGH | SSE endpoints, WebSocket bidirectional, async generators |2021| [Integrations](#integrations) | 2 | HIGH | Messaging platforms (WhatsApp, Telegram), Payload CMS patterns |2223**Total: 18 rules across 7 categories**2425## API Framework2627REST and GraphQL API design conventions for consistent, developer-friendly APIs.2829| Rule | File | Key Pattern |30|------|------|-------------|31| REST Conventions | `rules/framework-rest-conventions.md` | Plural nouns, HTTP methods, status codes, pagination |32| Resource Modeling | `rules/framework-resource-modeling.md` | Hierarchical URLs, filtering, sorting, field selection |33| OpenAPI | `rules/framework-openapi.md` | OpenAPI 3.1 specs, documentation, schema definitions |3435## Versioning3637Strategies for API evolution without breaking clients.3839| Rule | File | Key Pattern |40|------|------|-------------|41| URL Path | `rules/versioning-url-path.md` | `/api/v1/` prefix routing, version-specific schemas |42| Header | `rules/versioning-header.md` | `X-API-Version` header, content negotiation |43| Deprecation | `rules/versioning-deprecation.md` | Sunset headers, lifecycle management, breaking change policy |4445## Error Handling4647RFC 9457 Problem Details for machine-readable, standardized error responses.4849| Rule | File | Key Pattern |50|------|------|-------------|51| Problem Details | `rules/errors-problem-details.md` | RFC 9457 schema, `application/problem+json`, exception classes |52| Agent-Facing Errors | `rules/errors-agent-facing.md` | Agent extensions: `retryable`, `error_category`, content negotiation, token efficiency |53| Validation | `rules/errors-validation.md` | Field-level errors, Pydantic integration, 422 responses |54| Error Catalog | `rules/errors-error-catalog.md` | Problem type registry, error type URIs, client handling |5556## GraphQL5758Strawberry GraphQL code-first schema with type-safe resolvers and FastAPI integration.5960| Rule | File | Key Pattern |61|------|------|-------------|62| Schema Design | `rules/graphql-strawberry.md` | Type-safe schema, DataLoader, union errors, Private fields |63| Patterns & Auth | `rules/graphql-schema.md` | Permission classes, FastAPI integration, subscriptions |6465## gRPC6667High-performance gRPC for internal microservice communication.6869| Rule | File | Key Pattern |70|------|------|-------------|71| Service Definition | `rules/grpc-service.md` | Protobuf, async server, client timeout, code generation |72| Streaming & Interceptors | `rules/grpc-streaming.md` | Server/bidirectional streaming, auth, retry backoff |7374## Streaming7576Real-time data streaming with SSE, WebSockets, and proper cleanup.7778| Rule | File | Key Pattern |79|------|------|-------------|80| SSE | `rules/streaming-sse.md` | SSE endpoints, LLM streaming, reconnection, keepalive |81| WebSocket | `rules/streaming-websocket.md` | Bidirectional, heartbeat, aclosing(), backpressure |8283## Integrations8485Messaging platform integrations and headless CMS patterns.8687| Rule | File | Key Pattern |88|------|------|-------------|89| Messaging Platforms | `rules/messaging-integrations.md` | WhatsApp WAHA, Telegram Bot API, webhook security |90| Payload CMS | `rules/payload-cms.md` | Payload 3.0 collections, access control, CMS selection |9192## Quick Start Example9394```python95# REST endpoint with versioning and RFC 9457 errors96from fastapi import APIRouter, Depends, Request97from fastapi.responses import JSONResponse9899router = APIRouter()100101@router.get("/api/v1/users/{user_id}")102async def get_user(user_id: str, service: UserService = Depends()):103 user = await service.get_user(user_id)104 if not user:105 raise NotFoundProblem(106 resource="User",107 resource_id=user_id,108 )109 return UserResponseV1(id=user.id, name=user.full_name)110```111112## Key Decisions113114| Decision | Recommendation |115|----------|----------------|116| Versioning strategy | URL path (`/api/v1/`) for public APIs |117| Resource naming | Plural nouns, kebab-case |118| Pagination | Cursor-based for large datasets |119| Error format | RFC 9457 Problem Details with `application/problem+json` |120| Error type URI | Your API domain + `/problems/` prefix |121| Support window | Current + 1 previous version |122| Deprecation notice | 3 months minimum before sunset |123| Sunset period | 6 months after deprecation |124| GraphQL schema | Code-first with Strawberry types |125| N+1 prevention | DataLoader for all nested resolvers |126| GraphQL auth | Permission classes (context-based) |127| gRPC proto | One service per file, shared common.proto |128| gRPC streaming | Server stream for lists, bidirectional for real-time |129| SSE keepalive | Every 30 seconds |130| WebSocket heartbeat | ping-pong every 30 seconds |131| Async generator cleanup | aclosing() for all external resources |132133## Common Mistakes1341351. Verbs in URLs (`POST /createUser` instead of `POST /users`)1362. Inconsistent error formats across endpoints1373. Breaking contracts without version bump1384. Plain text error responses instead of Problem Details1395. Sunsetting versions without deprecation headers1406. Exposing internal details (stack traces, DB errors) in errors1417. Missing `Content-Type: application/problem+json` on error responses1428. Supporting too many concurrent API versions (max 2-3)1439. Caching without considering version isolation144145## Evaluations146147See `test-cases.json` for 9 test cases across all categories.148149## Related Skills150151- `fastapi-advanced` - FastAPI-specific implementation patterns152- `rate-limiting` - Advanced rate limiting implementations and algorithms153- `observability-monitoring` - Version usage metrics and error tracking154- `input-validation` - Validation patterns beyond API error handling155- `streaming-api-patterns` - SSE and WebSocket patterns for real-time APIs156157## Capability Details158159### rest-design160**Keywords:** rest, restful, http, endpoint, route, path, resource, CRUD161**Solves:**162- How do I design RESTful APIs?163- REST endpoint patterns and conventions164- HTTP methods and status codes165166### graphql-design167**Keywords:** graphql, schema, query, mutation, connection, relay168**Solves:**169- How do I design GraphQL APIs?170- Schema design best practices171- Connection pattern for pagination172173### endpoint-design174**Keywords:** endpoint, route, path, resource, CRUD, openapi175**Solves:**176- How do I structure API endpoints?177- What's the best URL pattern for this resource?178- RESTful endpoint naming conventions179180### url-versioning181**Keywords:** url version, path version, /v1/, /v2/182**Solves:**183- How to version REST APIs?184- URL-based API versioning185186### header-versioning187**Keywords:** header version, X-API-Version, content negotiation188**Solves:**189- Clean URL versioning190- Header-based API version191192### deprecation193**Keywords:** deprecation, sunset, version lifecycle, backward compatible194**Solves:**195- How to deprecate API versions?196- Version sunset policy197- Breaking vs non-breaking changes198199### problem-details200**Keywords:** problem details, RFC 9457, RFC 7807, structured error, application/problem+json201**Solves:**202- How to standardize API error responses?203- What format for API errors?204205### agent-facing-errors206**Keywords:** agent error, AI agent, retryable, retry_after, error_category, content negotiation, accept header, token efficient, machine readable207**Solves:**208- How to design error responses for AI agent consumers?209- How to reduce token cost of error responses?210- How to enable deterministic agent error handling?211- Content negotiation for agents vs browsers vs LLMs212213### validation-errors214**Keywords:** validation, field error, 422, unprocessable, pydantic215**Solves:**216- How to handle validation errors in APIs?217- Field-level error responses218219### error-registry220**Keywords:** error registry, problem types, error catalog, error codes221**Solves:**222- How to document all API errors?223- Error type management224225---226> Converted and distributed by [TomeVault](https://tomevault.io/claim/yonatangross) — claim your Tome and manage your conversions.227<!-- tomevault:4.0:skill_md:2026-04-11 -->