codejump

Dependency Basics — Series 3

Preview — 3 of 10 questions

A dependency declares page: int = Query(default=1, ge=1). What happens for ?page=0?

AThe route receives zero
BFastAPI silently changes it to one
CThe value is read from a cookie
DFastAPI returns a request validation error

A route consumes Annotated[str, Depends(get_name)]. Which value reaches the route parameter?

AThe string returned by get_name
BThe text get_name
CThe current URL path
DThe Depends metadata object

Can a dependency declare response: Response to set a response header?

ANo, only routes can access a Response object
BYes, FastAPI can inject the response object into a dependency
COnly when the dependency is an APIRouter
DOnly after the response has reached the client

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.