Concepts 🚀 Project 🧮 Labs
📚 Learn / Web & FastAPI / Routes & path operations

Routes & path operations

@router.get('/path') registers a function as the handler for GET requests to /path.

Code example

@router.get('/notebook')
async def notebook_page(request: Request):
    user = await get_current_user_from_cookie(request, db)
    return templates.TemplateResponse('notebook.html', {'user': user})

How it works

A route is a function that FastAPI calls when a matching HTTP request arrives. The decorator specifies the method (GET/POST/PUT/DELETE) and path. Path parameters like `/models/{id}` become function arguments. Query parameters like `?limit=10` are auto-parsed from the function signature. The function can be sync or async; FastAPI runs sync functions in a threadpool so they don't block the event loop.

🔍 Where this is used in OpenBenchML Every page and API endpoint in the app. There are 50+ routes across 11 route files.