home / skills / sickn33 / antigravity-awesome-skills / fastapi-router-py
This skill helps you generate FastAPI routers with CRUD, authentication, and proper response models for robust REST APIs.
npx playbooks add skill sickn33/antigravity-awesome-skills --skill fastapi-router-pyReview the files below or copy the command above to add this skill to your agents.
---
name: fastapi-router-py
description: 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.
---
# FastAPI Router
Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.
## Quick Start
Copy the template from [assets/template.py](assets/template.py) and replace placeholders:
- `{{ResourceName}}` → PascalCase name (e.g., `Project`)
- `{{resource_name}}` → snake_case name (e.g., `project`)
- `{{resource_plural}}` → plural form (e.g., `projects`)
## Authentication Patterns
```python
# Optional auth - returns None if not authenticated
current_user: Optional[User] = Depends(get_current_user)
# Required auth - raises 401 if not authenticated
current_user: User = Depends(get_current_user_required)
```
## Response Models
```python
@router.get("/items/{item_id}", response_model=Item)
async def get_item(item_id: str) -> Item:
...
@router.get("/items", response_model=list[Item])
async def list_items() -> list[Item]:
...
```
## HTTP Status Codes
```python
@router.post("/items", status_code=status.HTTP_201_CREATED)
@router.delete("/items/{id}", status_code=status.HTTP_204_NO_CONTENT)
```
## Integration Steps
1. Create router in `src/backend/app/routers/`
2. Mount in `src/backend/app/main.py`
3. Create corresponding Pydantic models
4. Create service layer if needed
5. Add frontend API functions
This skill scaffolds FastAPI routers with ready-made CRUD endpoints, authentication hooks, and correct response models. It speeds up creating REST routes by providing a copy-paste template and clear integration steps for service layers and frontend wiring. Use it to produce consistent, secure, and well-typed route modules in FastAPI projects.
The skill supplies a template router file with placeholders for resource names and pluralization. It adds optional and required authentication dependency patterns, response_model annotations, and proper HTTP status codes for create and delete operations. Follow the integration steps to place the router, mount it in the main app, add Pydantic models, and connect a service layer and frontend API calls.
How do I handle authentication in generated routers?
Use the provided dependency patterns: optional auth (Depends(get_current_user)) for public endpoints and required auth (Depends(get_current_user_required)) for protected endpoints.
Where do I put the generated router file?
Place it under src/backend/app/routers/, then import and include it in src/backend/app/main.py so the routes are mounted on the FastAPI app.