Fastapi Router Py
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Software development
- MIT
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The fastapi-router-py skill provides a structured approach to building REST API endpoints within FastAPI applications. It offers templates and patterns for implementing standard CRUD operations, integrating authentication dependencies, and defining response models. The skill includes guidance on HTTP status code management and best practices for handling asynchronous I/O and resource lifespans.
What it does
- Provides a template for creating new FastAPI routers.
- Demonstrates patterns for optional and required authentication dependencies.
- Shows how to define Pydantic response models for API endpoints.
- Outlines the use of appropriate HTTP status codes for different operations.
- Offers best practices for managing I/O and resource lifespans.
- Provides integration steps for mounting routers into a main application.
When to use it
- When you need to create new REST API endpoints in a FastAPI project.
- When implementing standard CRUD operations for a new resource.
- When adding authentication requirements to specific API routes.
- When you need to ensure consistent response models and status codes across your API.
Advantages
- Reduces boilerplate code through standardized templates.
- Ensures consistent implementation of authentication and status codes.
- Promotes best practices for asynchronous endpoint design.
- Simplifies the integration of new routers into existing FastAPI applications.
Usage examples
- “Create a new FastAPI router for a 'Product' resource.”
- The agent provides a template with placeholders for 'Product', 'product', and 'products', ready to be integrated into the application.
- “How do I require authentication for a specific endpoint?”
- The agent provides the code pattern using 'Depends(get_current_user_required)' to enforce authentication and return a 401 error if missing.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/microsoft/fastapi-router-py/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip fastapi-router-py.zip -d .agents/skills
Documentation by Microsoft
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 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
# 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
@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
@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
Create router in
src/backend/app/routers/Mount in
src/backend/app/main.pyCreate corresponding Pydantic models
Create service layer if needed
Add frontend API functions
Best Practices
Pick
deforasync defper endpoint based on whether you call async I/O; do not call blocking I/O from anasync defhandler.Manage long-lived resources (DB pools, HTTP clients) in
lifespanand inject viaDepends; usewith/async withfor per-request resources.
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
Files
- ATTRIBUTION.mdAdded by AutoGineer962 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md2.2 KiB
- assets/template.pyScript4.6 KiB
- references/capabilities.md934 B
LICENSE
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARERequirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-python/skills/fastapi-router-py · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download fastapi-router-py.zip