0
0
FastAPIframework~20 mins

FastAPI installation and setup - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FastAPI Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
1:00remaining
Correct command to install FastAPI with Uvicorn
Which command correctly installs FastAPI along with Uvicorn for running the server?
Apip install fastapi; uvicorn install
Bpip install fastapi-uvicorn
Cpip install fastapi --with uvicorn
Dpip install fastapi uvicorn
Attempts:
2 left
💡 Hint
Think about how Python packages are installed together using pip.
component_behavior
intermediate
1: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!"}
A{"message": "Hello, FastAPI!"}
BHello, FastAPI!
C404 Not Found error
D500 Internal Server Error
Attempts:
2 left
💡 Hint
FastAPI returns JSON responses by default from dictionary returns.
🔧 Debug
advanced
1: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"
ATypeError: FastAPI endpoint must return dict or Response, not str
BNo error, server runs and returns plain text 'Hello'
CSyntaxError: missing async keyword
DRuntimeError: Uvicorn not installed
Attempts:
2 left
💡 Hint
FastAPI can return strings directly as plain text responses.
🧠 Conceptual
advanced
1:00remaining
Purpose of Uvicorn in FastAPI setup
What is the main role of Uvicorn when used with FastAPI?
AIt is a database driver required for FastAPI to connect to databases
BIt is a frontend framework to build user interfaces for FastAPI apps
CIt is an ASGI server that runs the FastAPI app and handles requests asynchronously
DIt is a testing tool to check FastAPI app performance
Attempts:
2 left
💡 Hint
Think about what runs your app and listens for web requests.
state_output
expert
2: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"}
AServer is starting...
BNo output printed on startup
CError: on_event decorator not found
DServer is starting...\nGET / 200 OK
Attempts:
2 left
💡 Hint
The startup event runs once when the server launches.