Complete the code to import the FastAPI class.
from fastapi import [1] app = FastAPI()
The FastAPI class is imported to create the app instance which handles routing.
Complete the code to define a GET endpoint at path '/'.
@app.[1]("/") def read_root(): return {"message": "Hello World"}
The GET method defines an endpoint that responds to HTTP GET requests.
Fix the error in the route decorator to correctly organize the endpoint.
@app.[1]("/items/{item_id}") def read_item(item_id: int): return {"item_id": item_id}
The GET method is appropriate for reading an item by its ID in the URL path.
Fill both blanks to create a POST endpoint that accepts JSON data.
@app.[1]("/users") async def create_user(user: [2]): return user
POST is used to create resources. The user parameter is typed as dict to accept JSON data.
Fill all three blanks to organize endpoints with path and query parameters.
@app.[1]("/search") async def search_items(q: [2] = None, limit: [3] = 10): return {"query": q, "limit": limit}
GET method is used for searching. Query parameter q is a string, limit is an integer with default 10.
