Challenge - 5 Problems
FastAPI Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate1:00remaining
Correct command to install FastAPI with Uvicorn
Which command correctly installs FastAPI along with Uvicorn for running the server?
Attempts:
2 left
💡 Hint
Think about how Python packages are installed together using pip.
✗ Incorrect
The correct way to install FastAPI and Uvicorn together is by listing both packages separated by a space in one pip install command.
❓ component_behavior
intermediate1:30remaining
Behavior of a minimal FastAPI app
What will be the output when you visit
http://localhost:8000/ after running this FastAPI app code?FastAPI
from fastapi import FastAPI app = FastAPI() @app.get('/') async def read_root(): return {"message": "Hello, FastAPI!"}
Attempts:
2 left
💡 Hint
FastAPI returns JSON responses by default from dictionary returns.
✗ Incorrect
The function returns a dictionary, so FastAPI converts it to JSON automatically. The browser will show the JSON string.
🔧 Debug
advanced1:30remaining
Identify the error when running FastAPI app
What error will occur if you run this code and try to start the server with
uvicorn main:app --reload?FastAPI
from fastapi import FastAPI app = FastAPI() @app.get('/') def read_root(): return "Hello"
Attempts:
2 left
💡 Hint
FastAPI can return strings directly as plain text responses.
✗ Incorrect
FastAPI allows returning strings directly, which it sends as plain text. No error occurs.
🧠 Conceptual
advanced1:00remaining
Purpose of Uvicorn in FastAPI setup
What is the main role of Uvicorn when used with FastAPI?
Attempts:
2 left
💡 Hint
Think about what runs your app and listens for web requests.
✗ Incorrect
Uvicorn is a lightweight ASGI server that runs FastAPI apps and handles asynchronous web requests.
❓ state_output
expert2:00remaining
Output after modifying FastAPI app with startup event
Given this FastAPI app code, what will be printed to the console when the server starts?
FastAPI
from fastapi import FastAPI app = FastAPI() @app.on_event("startup") async def startup_event(): print("Server is starting...") @app.get('/') async def read_root(): return {"status": "running"}
Attempts:
2 left
💡 Hint
The startup event runs once when the server launches.
✗ Incorrect
The @app.on_event("startup") decorator runs the function when the server starts, printing the message once.