mcpField
F
fastapi-router-py

fastapi-router-py

github.com/sickn33Development48.7k139 installsUpdated today
Repository

About fastapi-router-py

A skill for creating FastAPI routers with authentication patterns, response models, and HTTP status codes. It provides a reusable template and emphasizes owner and tenant authorization checks for CRUD routes.

Key features

  1. 01FastAPI router template
  2. 02Optional and required authentication patterns
  3. 03Response models and HTTP status codes
  4. 04Owner and tenant authorization guidance

Use cases

  1. 01Scaffolding CRUD routers
  2. 02Adding authentication to API routes
  3. 03Reviewing ownership checks across CRUD endpoints

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/sickn33/agentic-awesome-skills --skill fastapi-router-py

After installing, type/fastapi-router-pyin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

UPSTREAM-LICENSE.txt
UPSTREAM-NOTICE.md
assets/
template.py

Details

From the project README

Bundled upstream support

Supporting files are included at skill-relative paths. See UPSTREAM-NOTICE.md for their pinned sources, licenses, hashes, and import changes.

FastAPI Router

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

Authorization requirements

The template assumes an author_id owner field; adapt it to the real model before use. Update/delete checks are required, not optional. For non-public resources require authentication and tenant/owner filtering on list/get too, preferably in atomic service queries; authentication alone is not authorization. Test anonymous access, another owner and another tenant against every CRUD route. The placeholder template is not executable Python until substituted and integrated.

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)
@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.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Comments

Markdown supported