Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import FastAPI from the correct package.
FastAPI
from [1] import FastAPI
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing FastAPI from Flask or Django.
Trying to import from requests.
✗ Incorrect
You import FastAPI from the fastapi package to create your app.
2fill in blank
mediumComplete the code to create a FastAPI app instance.
FastAPI
app = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flask() instead of FastAPI().
Trying to instantiate Request.
✗ Incorrect
You create an app by calling FastAPI().
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.post instead of @app.get for reading data.
Using wrong HTTP method decorators.
✗ Incorrect
The route decorator for a GET request is @app.get("/").
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.get instead of @app.post.
Mismatching parameter name and path variable.
✗ Incorrect
The POST decorator is @app.post and the function parameter must match the path variable name item_id.
5fill in blank
hardFill 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'
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.
✗ Incorrect
To run locally, use host "127.0.0.1", port 8000, and log level "info" for standard output.