0
0
FastAPIframework~10 mins

First FastAPI application - Interactive Code Practice

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

Complete the code to import FastAPI from the correct package.

FastAPI
from [1] import FastAPI
Drag options to blanks, or click blank then click option'
Adjango
Bflask
Cfastapi
Drequests
Attempts:
3 left
💡 Hint
Common Mistakes
Importing FastAPI from Flask or Django.
Trying to import from requests.
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'
AFlask
BRequest
CDjango
DFastAPI
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flask() instead of FastAPI().
Trying to instantiate Request.
3fill in blank
hard

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

FastAPI
@app.[1]("/")
def read_root():
    return {"Hello": "World"}
Drag options to blanks, or click blank then click option'
Adelete
Bget
Cpost
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.post instead of @app.get for reading data.
Using wrong HTTP method decorators.
4fill in blank
hard

Fill both blanks to define a POST endpoint at path '/items' that accepts a parameter named 'item_id'.

FastAPI
@app.[1]("/items/{item_id}")
async def create_item([2]: int):
    return {"item_id": item_id}
Drag options to blanks, or click blank then click option'
Apost
Bitem_id
Cget
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.get instead of @app.post.
Mismatching parameter name and path variable.
5fill in blank
hard

Fill all three blanks to run the FastAPI app with uvicorn on host '127.0.0.1' and port 8000.

FastAPI
import uvicorn

if __name__ == "__main__":
    uvicorn.run(app, host=[1], port=[2], log_level=[3])
Drag options to blanks, or click blank then click option'
A"0.0.0.0"
B8000
C"info"
D"127.0.0.1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using host 0.0.0.0 which exposes to all networks.
Using wrong port number.
Using incorrect log level string.