0
0
FastAPIframework~10 mins

Router prefix and tags in FastAPI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a router with prefix '/items'.

FastAPI
from fastapi import APIRouter

router = APIRouter(prefix=[1])
Drag options to blanks, or click blank then click option'
A'items/'
B"/items"
C"items"
D'/item'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash in the prefix string.
Using singular form instead of plural for resource path.
2fill in blank
medium

Complete the code to add tags to the router for documentation.

FastAPI
router = APIRouter(prefix="/users", tags=[1])
Drag options to blanks, or click blank then click option'
A["user"]
B"users"
C["users"]
D"user"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list.
Using singular form 'user' instead of plural 'users' for tags.
3fill in blank
hard

Fix the error in the router creation by completing the blank.

FastAPI
router = APIRouter(prefix=[1], tags=["items"])
Drag options to blanks, or click blank then click option'
A"/items"
Bitems
C'items/'
D"items"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted identifiers instead of strings.
Missing the leading slash in the prefix string.
4fill in blank
hard

Fill both blanks to create a router with prefix '/products' and tags ['products', 'inventory'].

FastAPI
router = APIRouter(prefix=[1], tags=[2])
Drag options to blanks, or click blank then click option'
A"/products"
B["products", "inventory"]
C["product", "stock"]
D"products"
Attempts:
3 left
💡 Hint
Common Mistakes
Using tags as a single string instead of a list.
Missing the leading slash in prefix.
5fill in blank
hard

Fill all three blanks to create a router with prefix '/orders', tags ['orders'], and include a GET endpoint '/list'.

FastAPI
router = APIRouter(prefix=[1], tags=[2])

@router.get([3])
async def list_orders():
    return {"message": "List of orders"}
Drag options to blanks, or click blank then click option'
A"/orders"
B["orders"]
C"/list"
D"list"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash in prefix or path.
Using tags as a string instead of a list.