APIRouter

noun

say it: “AY-pee-EYE ROW-ter” /ˌeɪpiˈaɪ ˈraʊtər/

A FastAPI object that groups related routes, often in a file of their own, which the main app adds with app.include_router and a shared prefix.

What is APIRouter?

APIRouter groups related endpoints in their own file, which the main app includes with a prefix.

router = APIRouter(prefix='/recipes', tags=['recipes'])

@router.get('/')
def list_recipes(): ...

app.include_router(router)

In a sentence

  • “main.py stays short because each APIRouter holds one resource's routes.”
  • “The games routes moved into their own file with an APIRouter and the prefix /games.”

Level: Journeyman · More FastAPI terms at this level

Updated