0
0
FastAPIframework~20 mins

First FastAPI application - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FastAPI First Steps Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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!'}
A{"message": "Hello, FastAPI!"}
B"Hello, FastAPI!"
C{"hello": "message"}
D404 Not Found error
Attempts:
2 left
💡 Hint
Look at the dictionary returned by the endpoint function.
📝 Syntax
intermediate
2: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}
AUsing async def with a return statement
BRemoving the colon after the function definition line
CChanging the route decorator to @app.get('/items/{item_id}') without quotes
DReturning a dictionary from the function
Attempts:
2 left
💡 Hint
Check Python function syntax carefully.
state_output
advanced
2: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}
ARaises an error due to global variable
B1
C3
D0
Attempts:
2 left
💡 Hint
Think about how global variables behave in a running FastAPI app.
🔧 Debug
advanced
2: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}
AUsing await inside a non-async function
BMissing return statement in fetch_data
CRoute decorator syntax is incorrect
Dfetch_data is not defined
Attempts:
2 left
💡 Hint
Check if the function using await is declared async.
🧠 Conceptual
expert
3:00remaining
Which option best describes FastAPI's automatic data validation?
FastAPI automatically validates request data using which feature?
AManual checks inside endpoint functions
BCustom middleware that intercepts requests
CUsing Python's built-in type hints without extra libraries
DPydantic models that define data schemas
Attempts:
2 left
💡 Hint
Think about how FastAPI knows what data to expect and how to check it.