Complete the code to define a route that matches the path '/items'.
from fastapi import FastAPI app = FastAPI() @app.get("[1]") def read_items(): return {"message": "List of items"}
The route decorator must match the exact path '/items' to handle requests to that path.
Complete the code to define a route that matches any item ID as a path parameter.
from fastapi import FastAPI app = FastAPI() @app.get("[1]") def read_item(item_id: int): return {"item_id": item_id}
The route must include a path parameter in curly braces to capture the item ID.
Fix the error in the route order to ensure the static route '/users/me' is matched before the dynamic route.
from fastapi import FastAPI app = FastAPI() @app.get("/users/me") def read_current_user(): return {"user": "current user"} @app.get("/users/[1]") def read_user(user_id: str): return {"user_id": user_id}
The dynamic route must use a path parameter like '{user_id}' to capture any user ID, while the static route '/users/me' should be defined before it to take priority.
Fill both blanks to create a route that matches a file path with an extension and a route that matches a specific file name.
from fastapi import FastAPI app = FastAPI() @app.get("/files/[2]") def read_readme(): return {"file": "README file"} @app.get("/files/[1]") def read_file(file_path: str): return {"file_path": file_path}
The first route uses a path parameter with ':path' to capture any file path including slashes. The second route matches the exact file name 'README.md'.
Fill all three blanks to create a dictionary comprehension that maps route names to their handler functions only if the route name starts with 'get'.
routes = {
[1]: [2] for [3] in route_list if [3].startswith('get')
}The comprehension uses 'route_name' as the key and 'handlers[route_name]' as the value, iterating over 'route_name' in 'route_list' and filtering names starting with 'get'.