fastapi-router-py — Claude Code skill: install and use
This skill builds FastAPI routers with CRUD handlers, auth dependencies, and response models. Use it when adding REST endpoints or protected routes.
npx skills add microsoft/skills --skill fastapi-router-py -a claude-codeWhat fastapi-router-py does
fastapi-router-py guides an agent through FastAPI router work using established endpoint patterns. It covers CRUD handlers, optional and required authentication dependencies, response models, and status codes for create and delete operations. Resource names are mapped to PascalCase, snake_case, and plural forms when the router is generated.
The integration path includes a router under src/backend/app/routers/, registration in src/backend/app/main.py, matching Pydantic models, and a service layer when the feature needs one. The skill also accounts for frontend API functions and keeps long-lived database pools or HTTP clients in lifespan, exposing them through Depends.
Blocking I/O inside an async def handler breaks the stated endpoint pattern. Choose def or async def based on the I/O you call, and use with or async with for per-request resources.
What it helps with
- create a FastAPI router for a resource
- add CRUD handlers to a REST API
- require authentication with
Depends - define response models and HTTP status codes
- register a router in
main.py
Example prompts for the agent
- Create a FastAPI router for a Project resource with CRUD handlers and response models.
- Add required authentication with
get_current_user_requiredand returnHTTP_201_CREATEDwhen a resource is created. - Place the router in
src/backend/app/routers/, register it insrc/backend/app/main.py, and add the matching Pydantic models.
How to install fastapi-router-py
1Skills CLI (Vercel)
npx skills add microsoft/skills --skill fastapi-router-py -a claude-code2Manually: put the files in place
~/.claude/skills/fastapi-router-py/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/fastapi-router-py/
Manually: put the files in place
.agents/skills/fastapi-router-py/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/fastapi-router-py/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install microsoft/skills fastapi-router-py2Manually: put the files in place
.github/skills/fastapi-router-py/SKILL.mdPlatform CLI
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-python/skills/fastapi-router-pyManually: put the files in place
.devin/skills/fastapi-router-py/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about fastapi-router-py
How do I install fastapi-router-py in Claude Code?
Run npx skills add microsoft/skills --skill fastapi-router-py -a claude-code, then use ~/.claude/skills/fastapi-router-py/SKILL.md.
What does fastapi-router-py do?
It helps create FastAPI routers with CRUD operations, authentication dependencies, response models, and HTTP status codes.
How does fastapi-router-py handle authentication?
Optional access uses Depends(get_current_user). Required access uses Depends(get_current_user_required) and raises 401 when the request is unauthenticated.
Source text
SKILL.md · MIT
---
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.
license: MIT
metadata:
author: Microsoft
version: "1.0.0"
---
# 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)
async def create_item(item: ItemCreate) -> Item:
...
@router.delete("/items/{id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_item(id: str) -> None:
...
```
## 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
## Best Practices
1. **Pick `def` or `async def` per endpoint based on whether you call async I/O; do not call blocking I/O from an `async def` handler.**
2. **Manage long-lived resources (DB pools, HTTP clients) in `lifespan` and inject via `Depends`;** use `with`/`async with` for per-request resources.
## Reference Files
| File | Contents |
|------|----------|
| [references/capabilities.md](references/capabilities.md) | Additional non-hero capabilities, operation-group coverage, and production checklists. |
© Microsoft · MIT · microsoft/skills