Defines how to implement controllers using APIRouter and an aggregator pattern
This skill defines how to structure API endpoints using APIRouter.
Each controller must define a router:
from fastapi import APIRouter
router = APIRouter(prefix="/api/example", tags=["Example"])
File name: <domain>_controller.py Use APIRouter, NOT app Always define prefix and tags Keep endpoints grouped by domain
Example:
from fastapi import APIRouter
router = APIRouter(prefix="/api/example", tags=["Example"])
@router.get("")
async def list_items():
return {"data": []}
from fastapi import APIRouter
router = APIRouter(prefix="/api/health", tags=["Health"])
@router.get("")
async def health_check():
return {"status": "healthy"}
All routers must be aggregated in this path: backend/controllers/init.py
from fastapi import APIRouter
from backend.controllers.health_controller import router as health_router
api_router = APIRouter()
api_router.include_router(health_router)
from backend.controllers import api_router
app.include_router(api_router)