new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · all subjects

path operations & parameters

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Declare Request object as path operation parameter

To access the Request object directly in a path operation function, declare a parameter with the type annotation Request. FastAPI will recognize this and pass the Request object to that parameter. You can declare the Request parameter alongside other normal parameters like path parameters, query parameters, and request bodies with Pydantic models.

Data taken directly from Request object is not validated or documented

When you access data directly from the Request object (such as reading its body), FastAPI does not validate, convert, or generate OpenAPI documentation for that data. However, other normally declared parameters in the same path operation function (such as body parameters using Pydantic models) are still validated, converted, annotated, and documented as usual.

Request object import source

The Request object can be imported from starlette.requests (from starlette.requests import Request). FastAPI provides it directly for convenience, but it comes directly from Starlette, which FastAPI uses under the hood.

Basic path operation with path parameters

Path parameters are declared in the decorator path string with curly braces and as function parameters with type hints. Example: @app.get("/items/{item_id}") def read_item(item_id: int, q: str | None = None): returns the item_id as an integer and optional query parameter q.

Optional query parameters with default None

Query parameters are made optional by giving them a default value of None in the function signature. Example: q: str | None = None makes the q parameter optional.

Give your agent this brain