PythiloLesson 8 of 14 · progress kept in this browser

Compose routes under a prefix

An APIRouter groups related routes without creating a separate network server. Including the router in an application composes its paths with a prefix. This separates feature-specific route definitions from the application's wiring.

A prefix is part of the public URL contract. Test the resulting complete URL, not only the router's local path. The route should not accidentally remain available without its prefix. Multiple independently created apps can include equivalent routers, which is useful for tests and for keeping application state out of module-level imports.

from fastapi import FastAPI, APIRouter
router = APIRouter()
@router.get("/ping")
async def ping():
    return {"ok": True}
app = FastAPI()
app.include_router(router, prefix="/v1")
print(list(app.openapi()["paths"]))
Your task

Implement build_app() using APIRouter: GET /api/v1/health returns {"status":"ok"}. The unprefixed /health path must return 404.

The first run loads fastapi, httpx into this browser.