Generated banner for Fastapi Router Py
Generated logo for Fastapi Router Py

Fastapi Router Py

MicrosoftOfficialCreated by Microsoft

  • Skill
  • Tool integration
  • Software development
  • MIT
  • Low risk
  • Has scripts

From the author

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.
— the description by Microsoft

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

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/microsoft/fastapi-router-py/download
  2. Unzip 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

  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

FileContents
references/capabilities.mdAdditional non-hero capabilities, operation-group coverage, and production checklists.

Files

Requirements 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