api-design-patterns
Guides RESTful API design. Use this for structured endpoints, validation, and error handling patterns.
Install
mkdir -p .claude/skills/api-design-patterns && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/18835" && unzip -o skill.zip -d .claude/skills/api-design-patterns && rm skill.zipInstalls to .claude/skills/api-design-patterns
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Apply RESTful and FastAPI design best practices for endpoints, error handling, validation, and DI. Use when designing APIs, creating new endpoints, or reviewing API structure with backend-architect.Key capabilities
- →Apply RESTful conventions for endpoint naming
- →Use appropriate HTTP status codes for API responses
- →Implement consistent error response shapes
- →Validate request models using Pydantic v2
- →Structure FastAPI applications with routers and dependencies
How it works
This skill provides guidelines and examples for designing APIs following RESTful principles and FastAPI best practices.
Inputs & outputs
When to use api-design-patterns
- →Structure new API endpoints
- →Design RESTful resources
- →Implement standard error handling
- →Refactor FastAPI router logic
About this skill
API Design Patterns (FastAPI)
Quick Reference
REST Conventions
- Nouns, not verbs:
/usersnot/get_users - Plural resources:
/productsnot/product - Nested for relationships:
/users/123/ordersfor user's orders - HTTP methods: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)
Status Codes
Use starlette.status (e.g. status.HTTP_200_OK). Return via HTTPException or response class.
| Code | Use |
|---|---|
| 200 | Success (GET, PUT, PATCH) |
| 201 | Created (POST) |
| 204 | No content (DELETE) |
| 400 | Bad request (validation failed) |
| 401 | Unauthorized (not authenticated) |
| 403 | Forbidden (authenticated but not allowed) |
| 404 | Not found |
| 409 | Conflict (duplicate, state conflict) |
| 422 | Unprocessable (FastAPI default for Pydantic validation errors) |
| 500 | Server error |
Error Response Shape
Keep consistent; e.g. use FastAPI exception handlers to return:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Human-readable message",
"details": [{ "field": "email", "reason": "Invalid format" }]
}
}
Use HTTPException(status_code=..., detail=...); never expose stack traces to client.
Validation
- Validate at boundary with Pydantic v2 request models (body, query, path)
- FastAPI returns 422 with field-level details for validation errors
- Use Pydantic validators and model_dump for response shape
Structure
- Routers: Group routes by resource; use
APIRouter(prefix="/users", tags=["users"]) - Dependencies: Use
Depends()for DB session, current user, auth; keep handlers thin - Async: Use async route handlers and async service functions for I/O
Security
- Never expose stack traces in production
- Log errors server-side (structlog); return generic messages to client
- Rate limit public or auth endpoints where applicable
- Validate content-type and body size; use Pydantic for request body limits
When not to use it
- →When designing APIs for non-FastAPI frameworks
- →When the user asks for implementation details not related to API design
- →When the user asks to expose stack traces to clients
Limitations
- →Specific to FastAPI framework
- →Does not cover API design for other frameworks
- →Does not expose stack traces to clients
How it compares
This skill offers a structured approach to API design within FastAPI, promoting consistency and maintainability compared to ad-hoc development.
Compared to similar skills
api-design-patterns side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| api-design-patterns (this skill) | 0 | 14d | No flags | Intermediate |
| fastapi-templates | 520 | 2mo | No flags | Intermediate |
| fastapi-pro | 79 | 3mo | No flags | Advanced |
| fastapi-router-py | 5 | 12d | No flags | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
fastapi-pro
sickn33
Build high-performance async APIs with FastAPI, SQLAlchemy 2.0, and Pydantic V2. Master microservices, WebSockets, and modern Python async patterns. Use PROACTIVELY for FastAPI development, async optimization, or API architecture.
fastapi-router-py
microsoft
Create FastAPI routers with CRUD operations, authentication dependencies, and proper response models. Use when building REST API endpoints, creating new routes, implementing CRUD operations, or adding authenticated endpoints in FastAPI applications.
pydantic-models-py
microsoft
Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants. Use when defining API request/response schemas, database models, or data validation in Python applications using Pydantic v2.
backend-architect
sickn33
Expert backend architect specializing in scalable API design, microservices architecture, and distributed systems. Masters REST/GraphQL/gRPC APIs, event-driven architectures, service mesh patterns, and modern backend frameworks. Handles service boundary definition, inter-service communication, resilience patterns, and observability. Use PROACTIVELY when creating new backend services or APIs.
supabase-python
alinaqi
FastAPI with Supabase and SQLAlchemy/SQLModel