Challenge - 5 Problems
FastAPI First Steps Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this FastAPI endpoint?
Consider this FastAPI app code. What will the endpoint
/hello return when accessed?FastAPI
from fastapi import FastAPI app = FastAPI() @app.get('/hello') async def say_hello(): return {'message': 'Hello, FastAPI!'}
Attempts:
2 left
💡 Hint
Look at the dictionary returned by the endpoint function.
✗ Incorrect
The endpoint returns a JSON response with a key 'message' and value 'Hello, FastAPI!'. FastAPI automatically converts the dictionary to JSON.
📝 Syntax
intermediate2:00remaining
Which option will cause a syntax error in this FastAPI app?
Identify the option that will cause a syntax error when running this FastAPI app code snippet.
FastAPI
from fastapi import FastAPI app = FastAPI() @app.get('/items/{item_id}') async def read_item(item_id: int): return {"item_id": item_id}
Attempts:
2 left
💡 Hint
Check Python function syntax carefully.
✗ Incorrect
Python functions require a colon at the end of the definition line. Removing it causes a SyntaxError.
❓ state_output
advanced2:00remaining
What is the value of
counter after 3 requests?Given this FastAPI app, what will be the value of
counter after three separate requests to /count?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 global variables behave in a running FastAPI app.
✗ Incorrect
The global variable increments by 1 on each request, so after 3 requests it will be 3.
🔧 Debug
advanced2:00remaining
Why does this FastAPI app raise a runtime error?
Examine the code and select the reason for the runtime error when accessing
/data.FastAPI
from fastapi import FastAPI app = FastAPI() @app.get('/data') def get_data(): return await fetch_data() def fetch_data(): return {"data": 123}
Attempts:
2 left
💡 Hint
Check if the function using await is declared async.
✗ Incorrect
You cannot use await inside a regular function; it must be inside an async function.
🧠 Conceptual
expert3:00remaining
Which option best describes FastAPI's automatic data validation?
FastAPI automatically validates request data using which feature?
Attempts:
2 left
💡 Hint
Think about how FastAPI knows what data to expect and how to check it.
✗ Incorrect
FastAPI uses Pydantic models to define and validate data automatically based on schemas.