FastAPI: a Python backend

Lesson 06 · 10 min

APIRouter and project structure

A main.py with forty routes is impossible to read. Split them into files.

10 minLesson 6 of 9Practice includedAsk AI on any point

APIRouter is a small app with its own routes. Each resource gets its own module with a router, a shared prefix, and tags for the docs. main.py only creates the app and calls include_router. You can attach dependencies to a whole router — for example, require sign-in for every admin route.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.