api-route-design
Use when designing RESTful API endpoints in FastAPI or Python projects. Triggers for: creating GET/POST/PUT/DELETE endpoints, request validation with Pydantic, response formatting with JSON schemas, status code selection, pagination, filtering, or sorting parameters. NOT for: GraphQL APIs, WebSocket handlers, or non-RESTful endpoints.
Best use case
api-route-design is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Use when designing RESTful API endpoints in FastAPI or Python projects. Triggers for: creating GET/POST/PUT/DELETE endpoints, request validation with Pydantic, response formatting with JSON schemas, status code selection, pagination, filtering, or sorting parameters. NOT for: GraphQL APIs, WebSocket handlers, or non-RESTful endpoints.
Use when designing RESTful API endpoints in FastAPI or Python projects. Triggers for: creating GET/POST/PUT/DELETE endpoints, request validation with Pydantic, response formatting with JSON schemas, status code selection, pagination, filtering, or sorting parameters. NOT for: GraphQL APIs, WebSocket handlers, or non-RESTful endpoints.
Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.
Practical example
Example input
Use the "api-route-design" skill to help with this workflow task. Context: Use when designing RESTful API endpoints in FastAPI or Python projects. Triggers for: creating GET/POST/PUT/DELETE endpoints, request validation with Pydantic, response formatting with JSON schemas, status code selection, pagination, filtering, or sorting parameters. NOT for: GraphQL APIs, WebSocket handlers, or non-RESTful endpoints.
Example output
A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.
When to use this skill
- Use this skill when you want a reusable workflow rather than writing the same prompt again and again.
When not to use this skill
- Do not use this when you only need a one-off answer and do not need a reusable workflow.
- Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/api-route-design/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How api-route-design Compares
| Feature / Agent | api-route-design | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Use when designing RESTful API endpoints in FastAPI or Python projects. Triggers for: creating GET/POST/PUT/DELETE endpoints, request validation with Pydantic, response formatting with JSON schemas, status code selection, pagination, filtering, or sorting parameters. NOT for: GraphQL APIs, WebSocket handlers, or non-RESTful endpoints.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# API Route Design Skill
Expert design and implementation of RESTful APIs with proper validation, response formatting, and HTTP semantics.
## Quick Reference
| Pattern | Example | Purpose |
|---------|---------|---------|
| List resource | `@router.get("/fees/", response_model=List[FeeOut])` | Retrieve collection |
| Get by ID | `@router.get("/fees/{fee_id}")` | Retrieve single resource |
| Create | `@router.post("/fees/", response_model=FeeOut, status_code=201)` | Create new resource |
| Update | `@router.put("/fees/{fee_id}")` | Full resource update |
| Patch | `@router.patch("/fees/{fee_id}")` | Partial resource update |
| Delete | `@router.delete("/fees/{fee_id}", status_code=204)` | Remove resource |
## URL Naming Conventions
```
/v1/{resource} # Collection endpoints
/v1/{resource}/{id} # Single resource endpoints
/v1/{resource}/{id}/sub # Nested resource endpoints
```
**Rules:**
- Use lowercase, hyphens for multi-word: `/student-fees` not `/studentFees`
- Use plural nouns for collections: `/users` not `/user`
- Use HTTP methods semantically: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)
## HTTP Status Codes
| Code | Usage | Example |
|------|-------|---------|
| 200 | OK | Successful GET, PUT, PATCH |
| 201 | Created | Successful POST (resource created) |
| 202 | Accepted | Async operation started |
| 204 | No Content | Successful DELETE |
| 400 | Bad Request | Invalid input, validation failed |
| 401 | Unauthorized | Missing or invalid auth |
| 403 | Forbidden | Authenticated but not authorized |
| 404 | Not Found | Resource doesn't exist |
| 422 | Unprocessable Entity | Validation errors (Pydantic) |
| 500 | Internal Server Error | Unexpected server error |
## Request Validation Patterns
### Path Parameters
```python
from fastapi import APIRouter, HTTPException
from typing import Annotated
router = APIRouter()
@router.get("/fees/{fee_id}")
async def get_fee(fee_id: int):
fee = await get_fee_by_id(fee_id)
if not fee:
raise HTTPException(status_code=404, detail="Fee not found")
return fee
```
### Query Parameters (Pagination, Filtering, Sorting)
```python
@router.get("/fees/", response_model=List[FeeOut])
async def list_fees(
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
status: str | None = Query(None, pattern="^(pending|paid|overdue)$"),
sort_by: str = Query("created_at", enum=["created_at", "amount", "due_date"]),
sort_order: str = Query("desc", enum=["asc", "desc"]),
):
return await paginate_fees(
skip=skip,
limit=limit,
status=status,
sort_by=sort_by,
sort_order=sort_order,
)
```
### Request Body (Pydantic Models)
```python
from pydantic import BaseModel
from datetime import datetime
class FeeCreate(BaseModel):
student_id: int
amount: float = Field(..., gt=0)
due_date: datetime
description: str | None = None
class FeeUpdate(BaseModel):
amount: float | None = Field(None, gt=0)
status: str | None = Field(None, pattern="^(pending|paid|overdue)$")
due_date: datetime | None = None
@router.post("/fees/", response_model=FeeOut, status_code=201)
async def create_fee(fee_in: FeeCreate):
return await create_fee_db(fee_in)
@router.patch("/fees/{fee_id}", response_model=FeeOut)
async def update_fee(fee_id: int, fee_in: FeeUpdate):
return await update_fee_db(fee_id, fee_in)
```
## Response Models
### Standard Response Envelope
```python
class FeeOut(BaseModel):
id: int
student_id: int
amount: float
status: str
created_at: datetime
due_date: datetime
class PaginatedResponse(BaseModel):
data: List[FeeOut]
total: int
skip: int
limit: int
has_more: bool
```
### Error Response
```python
class ErrorResponse(BaseModel):
error: str
detail: str | None = None
code: str | None = None
```
## Complete Endpoint Example
```python
from fastapi import APIRouter, Depends, HTTPException, Query, status
from typing import List, Annotated
router = APIRouter(prefix="/v1/fees", tags=["fees"])
@router.get(
"/",
response_model=PaginatedResponse[FeeOut],
summary="List fees",
description="Retrieve a paginated list of fees with optional filtering.",
)
async def list_fees(
skip: Annotated[int, Query(0, ge=0)] = 0,
limit: Annotated[int, Query(100, ge=1, le=1000)] = 100,
status: Annotated[str | None, Query(pattern="^(pending|paid|overdue)$")] = None,
_current_user: User = Depends(get_current_user),
) -> PaginatedResponse[FeeOut]:
fees, total = await get_fees(
skip=skip, limit=limit, status=status, user=_current_user
)
return PaginatedResponse(
data=fees,
total=total,
skip=skip,
limit=limit,
has_more=(skip + limit) < total,
)
@router.get(
"/{fee_id}",
response_model=FeeOut,
responses={404: {"model": ErrorResponse}},
)
async def get_fee(
fee_id: int,
_current_user: User = Depends(get_current_user),
) -> FeeOut:
fee = await get_fee_by_id(fee_id)
if not fee:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Fee not found",
)
return fee
@router.post(
"/",
response_model=FeeOut,
status_code=status.HTTP_201_CREATED,
responses={400: {"model": ErrorResponse}},
)
async def create_fee(
fee_in: FeeCreate,
_current_user: User = Depends(get_current_user),
) -> FeeOut:
return await create_fee_db(fee_in, created_by=_current_user.id)
```
## Integration with Other Skills
| Skill | Integration Point |
|-------|-------------------|
| `@fastapi-app` | Router registration in `main.py` |
| `@sqlmodel-crud` | Database operations in endpoints |
| `@jwt-auth` | `Depends(get_current_user)` for protected routes |
| `@api-client` | Consumer of this API design |
## Quality Checklist
- [ ] **Pagination standard**: Use `skip`/`limit` with `has_more` indicator
- [ ] **Filtering**: Query params for common filter fields
- [ ] **Sorting**: `sort_by` and `sort_order` parameters
- [ ] **Status codes**: 201 for POST, 204 for DELETE, 404 for not found
- [ ] **Response models**: All endpoints use `response_model`
- [ ] **Documentation**: `summary` and `description` for OpenAPI
- [ ] **Error handling**: Consistent error response format
## Pagination Standard
```python
@router.get("/items/", response_model=PaginatedResponse[ItemOut])
async def list_items(
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
) -> PaginatedResponse[ItemOut]:
items, total = await get_items(skip=skip, limit=limit)
return PaginatedResponse(
data=items,
total=total,
skip=skip,
limit=limit,
has_more=(skip + limit) < total,
)
```
## Filtering & Sorting Standard
```python
@router.get("/items/")
async def list_items(
# Filtering
category: str | None = None,
status: str | None = Query(None, pattern="^(active|inactive)$"),
min_amount: float | None = Query(None, ge=0),
# Sorting
sort_by: str = Query("created_at", enum=["created_at", "amount", "name"]),
sort_order: str = Query("desc", enum=["asc", "desc"]),
):
return await get_items(
filters={"category": category, "status": status, "min_amount": min_amount},
order_by=f"{sort_order} {sort_by.lstrip('-')}",
)
```Related Skills
ui-design
UI 样式修改协作流程。当用户要求修改页面样式、调整布局、改 UI 细节时使用。通过"截图定位 → 现状描述 → 方案选择 → 改代码 → 微调"的结构化流程,减少沟通偏差,避免浪费 token。
design-exploration
新功能设计探索流程。当用户有模糊想法要做新功能/新模块时使用。通过"需求收敛 → 技术调研 → ASCII 批量探索 → HTML 设计稿 → 全状态覆盖 → 需求总结"的结构化流程,从模糊想法产出可交付的设计参考文档,作为 PRD 阶段的输入。
web-component-design
Master React, Vue, and Svelte component patterns including CSS-in-JS, composition strategies, and reusable component architecture. Use when building UI component libraries, designing component APIs, or implementing frontend design systems.
visual-design-foundations
Apply typography, color theory, spacing systems, and iconography principles to create cohesive visual designs. Use when establishing design tokens, building style guides, or improving visual hierarchy and consistency.
react-native-design
Master React Native styling, navigation, and Reanimated animations for cross-platform mobile development. Use when building React Native apps, implementing navigation patterns, or creating performant animations.
python-design-patterns
Python design patterns including KISS, Separation of Concerns, Single Responsibility, and composition over inheritance. Use when making architecture decisions, refactoring code structure, or evaluating when abstractions are appropriate.
postgresql-table-design
Design a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features
mobile-ios-design
Master iOS Human Interface Guidelines and SwiftUI patterns for building native iOS apps. Use when designing iOS interfaces, implementing SwiftUI views, or ensuring apps follow Apple's design principles.
mobile-android-design
Master Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.
interaction-design
Design and implement microinteractions, motion design, transitions, and user feedback patterns. Use when adding polish to UI interactions, implementing loading states, or creating delightful user experiences.
design-system-patterns
Build scalable design systems with design tokens, theming infrastructure, and component architecture patterns. Use when creating design tokens, implementing theme switching, building component libraries, or establishing design system foundations.
routeros-qemu-chr
MikroTik RouterOS CHR (Cloud Hosted Router) with QEMU. Use when: running RouterOS in QEMU, booting CHR images, debugging CHR boot failures, setting up VirtIO devices for RouterOS, choosing between SeaBIOS and UEFI boot, configuring QEMU port forwarding for RouterOS REST API, or selecting QEMU acceleration (KVM/HVF/TCG).