Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import APIRouter from FastAPI.
FastAPI
from fastapi import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing FastAPI instead of APIRouter
Using Request or Depends which are unrelated here
✗ Incorrect
You import APIRouter from FastAPI to create modular route groups.
2fill in blank
mediumComplete the code to create a new APIRouter instance.
FastAPI
router = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to create FastAPI instance instead of APIRouter
Using Depends or Request which are not constructors
✗ Incorrect
You create a router by calling APIRouter().
3fill in blank
hardFix the error in the route decorator to use the router instead of app.
FastAPI
@[1].get("/items") async def read_items(): return [{"item_id": "foo"}]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.get instead of @router.get
Using FastAPI or Depends in decorator
✗ Incorrect
Routes in modular files use the router instance, not the main app.
4fill in blank
hardFill both blanks to include the router in the main FastAPI app.
FastAPI
from fastapi import FastAPI app = FastAPI() app.[1](router, prefix=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using add_route which is not for routers
Wrong prefix string or missing quotes
✗ Incorrect
You add modular routes to the main app using include_router with a prefix path.
5fill in blank
hardFill all three blanks to define a router with a GET route and include it in the app with prefix.
FastAPI
from fastapi import FastAPI, [1] router = [1]() @router.get("/hello") async def say_hello(): return {"message": "Hello"} app = FastAPI() app.[2](router, prefix=[3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FastAPI instead of APIRouter for router
Wrong method name to include router
Missing quotes around prefix
✗ Incorrect
This shows the full pattern: import APIRouter, create router, define route, then include router in app with prefix.