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.
Add this skill
npx mdskills install sickn33/fastapi-router-pyClear template-based approach with authentication patterns and integration steps
1---2name: fastapi-router-py3description: 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.4---56# FastAPI Router78Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.910## Quick Start1112Copy the template from [assets/template.py](assets/template.py) and replace placeholders:13- `{{ResourceName}}` → PascalCase name (e.g., `Project`)14- `{{resource_name}}` → snake_case name (e.g., `project`)15- `{{resource_plural}}` → plural form (e.g., `projects`)1617## Authentication Patterns1819```python20# Optional auth - returns None if not authenticated21current_user: Optional[User] = Depends(get_current_user)2223# Required auth - raises 401 if not authenticated24current_user: User = Depends(get_current_user_required)25```2627## Response Models2829```python30@router.get("/items/{item_id}", response_model=Item)31async def get_item(item_id: str) -> Item:32 ...3334@router.get("/items", response_model=list[Item])35async def list_items() -> list[Item]:36 ...37```3839## HTTP Status Codes4041```python42@router.post("/items", status_code=status.HTTP_201_CREATED)43@router.delete("/items/{id}", status_code=status.HTTP_204_NO_CONTENT)44```4546## Integration Steps47481. Create router in `src/backend/app/routers/`492. Mount in `src/backend/app/main.py`503. Create corresponding Pydantic models514. Create service layer if needed525. Add frontend API functions53
Full transparency — inspect the skill content before installing.