Challenge - 5 Problems
FastAPI Connection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a FastAPI app receives a GET request?
Consider a FastAPI app with this route:
What is the output when a client sends a GET request to
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello")
async def say_hello():
return {"message": "Hello!"}What is the output when a client sends a GET request to
/hello?FastAPI
from fastapi import FastAPI app = FastAPI() @app.get("/hello") async def say_hello(): return {"message": "Hello!"}
Attempts:
2 left
💡 Hint
Think about what the return value of the route function means in FastAPI.
✗ Incorrect
FastAPI automatically converts the returned dictionary into JSON and sends it as the response body with the correct content type.
📝 Syntax
intermediate2:00remaining
Which code correctly starts a FastAPI server on port 8080?
You want to run your FastAPI app on port 8080 using uvicorn. Which code snippet below does this correctly?
Attempts:
2 left
💡 Hint
Check the parameter names and types uvicorn.run expects.
✗ Incorrect
uvicorn.run requires host as a string and port as an integer. Option C uses correct parameter names and types.
🔧 Debug
advanced2:00remaining
Why does this FastAPI app fail to accept connections?
Given this code:
You run
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"msg": "Hi"}You run
uvicorn main:app but get no response on http://localhost:8000/. What is the likely cause?FastAPI
from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"msg": "Hi"}
Attempts:
2 left
💡 Hint
Check the command and the app variable name in the code.
✗ Incorrect
uvicorn expects the app variable to be named exactly as specified after the colon. If the app variable name is different, uvicorn won't find it.
❓ state_output
advanced2:00remaining
What is the output after multiple requests to this FastAPI app?
Consider this FastAPI app:
If a client sends 3 GET requests to
from fastapi import FastAPI
app = FastAPI()
counter = 0
@app.get("/count")
async def count():
global counter
counter += 1
return {"count": counter}If a client sends 3 GET requests to
/count in a row, what is the JSON response to the third request?FastAPI
from fastapi import FastAPI app = FastAPI() counter = 0 @app.get("/count") async def count(): global counter counter += 1 return {"count": counter}
Attempts:
2 left
💡 Hint
Think about how the global variable changes with each request.
✗ Incorrect
The global counter increments by 1 on each request. After 3 requests, it will be 3.
🧠 Conceptual
expert2:00remaining
Which statement about FastAPI connection handling is true?
FastAPI uses ASGI servers like uvicorn to accept connections. Which of these statements is correct?
Attempts:
2 left
💡 Hint
Think about how async functions and ASGI servers work together.
✗ Incorrect
FastAPI leverages async functions and ASGI servers to handle many connections at once without blocking.