Challenge - 5 Problems
FastAPI Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this FastAPI endpoint response?
Given this FastAPI endpoint code, what will be the JSON response when a GET request is made to
/items/42?MLOps
from fastapi import FastAPI app = FastAPI() @app.get('/items/{item_id}') async def read_item(item_id: int): return {"item_id": item_id, "name": f"Item {item_id}"}
Attempts:
2 left
💡 Hint
Remember that FastAPI converts path parameters to the declared type.
✗ Incorrect
The endpoint returns a JSON with item_id as an integer and name as a string with capital 'I'. Option C matches exactly.
❓ Configuration
intermediate1:30remaining
Which uvicorn command correctly runs the FastAPI app from
main.py with auto-reload?You have a FastAPI app in
main.py with the app instance named app. Which command will start the server with auto-reload enabled?Attempts:
2 left
💡 Hint
The syntax is
uvicorn module_name:app_instance.✗ Incorrect
The correct syntax is uvicorn main:app --reload. The module name is main without the .py extension, and app is the FastAPI instance.
🔀 Workflow
advanced2:00remaining
What is the correct sequence to deploy a FastAPI app with Docker?
Arrange these steps in the correct order to build and run a FastAPI app using Docker.
Attempts:
2 left
💡 Hint
Think about writing the Dockerfile before building the image.
✗ Incorrect
You must first write the Dockerfile, then build the image, run the container, and finally test the API.
❓ Troubleshoot
advanced1:30remaining
Why does this FastAPI app raise a 422 error on POST?
This FastAPI endpoint expects JSON with
name (string) and age (int). The client sends {"name": "Alice", "age": "25"}. Why does the server respond with status 422?MLOps
from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class User(BaseModel): name: str age: int @app.post('/users') async def create_user(user: User): return user
Attempts:
2 left
💡 Hint
Check the data types expected by Pydantic models.
✗ Incorrect
Pydantic expects age as an integer, but the client sent it as a string, causing validation to fail and return 422.
✅ Best Practice
expert2:00remaining
Which approach best improves FastAPI app performance under high load?
You want to improve the performance of a FastAPI app serving ML model predictions under heavy traffic. Which option is the best practice?
Attempts:
2 left
💡 Hint
Consider how to handle many requests efficiently in production.
✗ Incorrect
Gunicorn with multiple workers and uvicorn workers allows handling many requests concurrently, improving performance under load.