0
0
FastAPIframework~10 mins

Why routing organizes endpoints in FastAPI - Test Your Understanding

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

Complete the code to import the FastAPI class.

FastAPI
from fastapi import [1]
app = FastAPI()
Drag options to blanks, or click blank then click option'
AResponse
BRequest
CFastAPI
DDepends
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request or Response instead of FastAPI.
2fill in blank
medium

Complete the code to define a GET endpoint at path '/'.

FastAPI
@app.[1]("/")
def read_root():
    return {"message": "Hello World"}
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using post or put instead of get for a read endpoint.
3fill in blank
hard

Fix the error in the route decorator to correctly organize the endpoint.

FastAPI
@app.[1]("/items/{item_id}")
def read_item(item_id: int):
    return {"item_id": item_id}
Drag options to blanks, or click blank then click option'
Apost
Bget
Cpatch
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using post or put which are for creating or updating data.
4fill in blank
hard

Fill both blanks to create a POST endpoint that accepts JSON data.

FastAPI
@app.[1]("/users")
async def create_user(user: [2]):
    return user
Drag options to blanks, or click blank then click option'
Apost
Bget
Cdict
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST or wrong parameter type.
5fill in blank
hard

Fill all three blanks to organize endpoints with path and query parameters.

FastAPI
@app.[1]("/search")
async def search_items(q: [2] = None, limit: [3] = 10):
    return {"query": q, "limit": limit}
Drag options to blanks, or click blank then click option'
Aget
Bstr
Cint
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST for search or wrong parameter types.