Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to install FastAPI using pip.
FastAPI
pip install [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Installing the wrong package like django or flask.
Forgetting to use pip before the package name.
✗ Incorrect
Use pip install fastapi to install the FastAPI framework.
2fill in blank
mediumComplete the code to install the ASGI server needed to run FastAPI.
FastAPI
pip install [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Installing gunicorn which is for WSGI apps.
Using servers not compatible with ASGI.
✗ Incorrect
FastAPI commonly uses uvicorn as the ASGI server to run the app.
3fill in blank
hardFix the error in the FastAPI app import statement.
FastAPI
from [1] import FastAPI app = FastAPI()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using capital letters in the module name.
Trying to import from 'FastAPI' instead of 'fastapi'.
✗ Incorrect
The correct module name to import FastAPI from is fastapi all lowercase.
4fill in blank
hardFill both blanks to create a basic FastAPI app and run it with uvicorn.
FastAPI
from fastapi import FastAPI app = FastAPI() if __name__ == "__main__": import [1] [2].run(app, host="127.0.0.1", port=8000)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong module to run the app.
Using the app variable instead of the server module to run.
✗ Incorrect
To run the FastAPI app, import uvicorn and call uvicorn.run() with the app instance.
5fill in blank
hardFill all three blanks to create a FastAPI app with a root path that returns a welcome message.
FastAPI
from fastapi import FastAPI app = FastAPI() @app.[1]("/") def read_root(): return [2]([3]: "Welcome to FastAPI!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.post instead of @app.get for the root path.
Returning a string directly instead of a dictionary.
Missing quotes around the dictionary key.
✗ Incorrect
The root path uses the @app.get("/") decorator. The function returns a dictionary with a key "message" and a welcome string.