Complete the code to import the Depends function from FastAPI.
from fastapi import [1]
The Depends function is imported from FastAPI to declare dependencies in your path operation functions.
Complete the code to declare a dependency function that returns a fixed string.
def get_token(): return [1]
The dependency function should return a string literal, so it must be quoted.
Fix the error in the FastAPI path operation to use Depends correctly.
from fastapi import FastAPI, Depends app = FastAPI() def get_token(): return "token123" @app.get("/items/") async def read_items(token: str = [1]): return {"token": token}
When declaring a dependency, you pass the function itself to Depends without calling it.
Fill both blanks to create a dependency that extracts a query parameter named 'q'.
from fastapi import Query def get_query(q: str = [1]): return q @app.get("/search") async def search(query: str = [2]): return {"query": query}
Use Query(...) to declare a required query parameter, and use Depends(get_query) to inject the dependency.
Fill all three blanks to create a dependency that reads a header and uses it in a path operation.
from fastapi import Header, Depends async def get_user_agent(user_agent: str = [1]): return user_agent @app.get("/info") async def info(agent: str = [2]): return {"User-Agent": [3]
Use Header(...) to require the header, Depends(get_user_agent) to inject the dependency, and return the parameter agent in the response.