0
0
FastAPIframework~10 mins

Why FastAPI exists - 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 FastAPI correctly.

FastAPI
from fastapi import [1]
Drag options to blanks, or click blank then click option'
ARequest
BResponse
CFastAPI
DDepends
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request instead of FastAPI
Using lowercase fastapi
2fill in blank
medium

Complete the code to create a FastAPI app instance.

FastAPI
app = [1]()
Drag options to blanks, or click blank then click option'
AFastAPI
BFlask
CDjango
DStarlette
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flask() instead of FastAPI()
Using lowercase fastapi()
3fill in blank
hard

Fix the error in the route decorator to define a GET endpoint.

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 instead of get
Using put or delete for a simple read route
4fill in blank
hard

Fill both blanks to create a path parameter and return it in the response.

FastAPI
@app.get("/items/[1]")
async def read_item([2]: int):
    return {"item_id": [2]
Drag options to blanks, or click blank then click option'
Aitem_id
Bitem
Cid
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in path and function
Using generic names like id or name
5fill in blank
hard

Fill all three blanks to create a POST endpoint that accepts a JSON body with a Pydantic model.

FastAPI
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: float

@app.post("/items/")
async def create_item([1]: [2]):
    return {"item_name": [3].name, "item_price": [3].price}
Drag options to blanks, or click blank then click option'
Aitem
BItem
Cdata
DBaseModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using BaseModel as type instead of the specific model
Mismatching parameter names