fastapi-router-py

Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.

31,392 stars
Complexity: easy

About this skill

This AI agent skill empowers you to rapidly scaffold FastAPI router code. It leverages established patterns to ensure generated routers are consistent, secure, and follow best practices. The skill guides the agent to use a provided template to automatically inject proper authentication mechanisms (optional or required), define clear response models for API clarity, and set appropriate HTTP status codes for robust error handling and success responses. This streamlines the development of new API endpoints, reduces boilerplate, and maintains code quality across FastAPI projects, making it ideal for quickly expanding or prototyping FastAPI applications.

Best use case

Rapidly prototype or expand a FastAPI application by generating new API endpoints that adhere to consistent architectural patterns.

Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.

A complete, functional Python file containing a FastAPI router for a specified resource, adhering to the skill's established patterns for authentication, response models, and HTTP status codes. The generated code will be ready for integration into a FastAPI application.

Practical example

Example input

Generate a new FastAPI router for a 'Product' resource. It should include optional authentication for read operations and required authentication for create/update/delete operations. Use the standard snake_case for resource names and PascalCase for resource names in the code.

Example output

```python
# Example generated content (abbreviated)
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, status
from pydantic import BaseModel

# Assuming User model and get_current_user dependency are available
# from your auth module
# from ...auth import get_current_user, User

router = APIRouter(prefix="/products", tags=["products"])

class ProductBase(BaseModel):
    name: str
    description: Optional[str] = None
    price: float

class ProductCreate(ProductBase):
    pass

class ProductResponse(ProductBase):
    id: int
    owner_id: int # Example for a created resource

    class Config:
        orm_mode = True

@router.post("/", response_model=ProductResponse, status_code=status.HTTP_201_CREATED)
async def create_product(product: ProductCreate, current_user: User = Depends(get_current_user)):
    # Logic to create product, associating with current_user.id
    # For demonstration:
    new_product_id = 123
    return ProductResponse(id=new_product_id, owner_id=current_user.id, **product.dict())

@router.get("/{product_id}", response_model=ProductResponse)
async def read_product(product_id: int, current_user: Optional[User] = Depends(get_current_user)):
    # Logic to fetch product
    # If product not found, raise HTTPException
    if product_id == 123:
         return ProductResponse(id=123, owner_id=1, name="Example Product", description="A sample product", price=99.99)
    raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Product not found")

# ... more routes (PUT, DELETE) following similar patterns
```

When to use this skill

  • When an AI agent needs to generate new CRUD endpoints for a FastAPI service quickly.
  • To ensure all new API routes follow a consistent structure, including authentication, request/response models, and status codes.
  • For developers looking to scaffold new resources in an existing FastAPI project with minimal manual effort.
  • When the agent is tasked with adding specific features to an API that require new routes.

When not to use this skill

  • For highly specialized or unique API designs that deviate significantly from standard RESTful patterns.
  • When working with existing, complex routers that require intricate modifications rather than new generation.
  • If the project already utilizes a different, more comprehensive code generation framework for FastAPI.
  • For tasks that involve only minor modifications to existing route definitions (e.g., changing a single status code).

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/fastapi-router-py/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/fastapi-router-py/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/fastapi-router-py/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How fastapi-router-py Compares

Feature / Agentfastapi-router-pyStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# 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

```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

## When to Use
This skill is applicable to execute the workflow or actions described in the overview.

Related Skills

fastapi-templates

31392
from sickn33/antigravity-awesome-skills

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

Code GenerationClaude

new-rails-project

31392
from sickn33/antigravity-awesome-skills

Create a new Rails project

Code GenerationClaude

makepad-widgets

31392
from sickn33/antigravity-awesome-skills

Version: makepad-widgets (dev branch) | Last Updated: 2026-01-19 > > Check for updates: https://crates.io/crates/makepad-widgets

Code GenerationClaude

makepad-splash

31392
from sickn33/antigravity-awesome-skills

CRITICAL: Use for Makepad Splash scripting language. Triggers on: splash language, makepad script, makepad scripting, script!, cx.eval, makepad dynamic, makepad AI, splash 语言, makepad 脚本

Code GenerationClaude

makepad-dsl

31392
from sickn33/antigravity-awesome-skills

CRITICAL: Use for Makepad DSL syntax and inheritance. Triggers on: makepad dsl, live_design, makepad inheritance, makepad prototype, "<Widget>", "Foo = { }", makepad object, makepad property, makepad DSL 语法, makepad 继承, makepad 原型, 如何定义 makepad 组件

Code GenerationClaude

javascript-typescript-typescript-scaffold

31392
from sickn33/antigravity-awesome-skills

You are a TypeScript project architecture expert specializing in scaffolding production-ready Node.js and frontend applications. Generate complete project structures with modern tooling (pnpm, Vite, N

Code GenerationClaude

frontend-ui-dark-ts

31392
from sickn33/antigravity-awesome-skills

A modern dark-themed React UI system using Tailwind CSS and Framer Motion. Designed for dashboards, admin panels, and data-rich applications with glassmorphism effects and tasteful animations.

Code GenerationClaude

frontend-mobile-development-component-scaffold

31392
from sickn33/antigravity-awesome-skills

You are a React component architecture expert specializing in scaffolding production-ready, accessible, and performant components. Generate complete component implementations with TypeScript, tests, s

Code GenerationClaude

frontend-dev-guidelines

31392
from sickn33/antigravity-awesome-skills

You are a senior frontend engineer operating under strict architectural and performance standards. Use when creating components or pages, adding new features, or fetching or mutating data.

Code GenerationClaude

fp-backend

31392
from sickn33/antigravity-awesome-skills

Functional programming patterns for Node.js/Deno backend development using fp-ts, ReaderTaskEither, and functional dependency injection

Code GenerationClaudeChatGPTGemini

dotnet-backend

31392
from sickn33/antigravity-awesome-skills

Build ASP.NET Core 8+ backend services with EF Core, auth, background jobs, and production API patterns.

Code GenerationClaude

core-components

31392
from sickn33/antigravity-awesome-skills

Core component library and design system patterns. Use when building UI, using design tokens, or working with the component library.

Code GenerationClaude