Requests and responses¶
Request
¶
Immutable view of an incoming HTTP request, handed to the Python handler.
frozen means no Python-side mutation, so no locking is needed even on
free-threaded builds.
body
property
¶
The raw request body. A pydantic-annotated argument is the usual way to read a body; this is for handlers that parse it themselves.
headers
property
¶
Every header, lowercased. Repeated headers are joined with ", " as HTTP itself defines.
query
property
¶
The raw query string, or None. Declared query parameters are already coerced and passed as handler arguments; this is for the rest.
header
method descriptor
¶
One header by name, case-insensitively. None if absent.
This is the cheap path: no dict is built, and a header that is not valid UTF-8 reads as absent rather than raising.
Response
dataclass
¶
Response(
body: bytes | str = b"",
status: int = 200,
content_type: str = "application/json",
headers: dict[str, str] = dict(),
)
A ready-to-send response.
body may be bytes or str; str is encoded as UTF-8. headers are sent in
addition to the content type.
encoded
¶
Reply
¶
A handler's result on its way back out.
value is whatever the handler returned: a dict, a model, a Response, an
SSE, or None. status overrides what that value would otherwise imply.
headers are added to the response.