On this page
HTTP request wrapper providing lazy body parsing, query parameter extraction, JSON deserialization via msgspec, header access, and per-request state.
#src.fastware.request
#src.fastware.request
HTTP request wrapper providing lazy body parsing, query parameter extraction, JSON deserialization via msgspec, header access, and per-request state.
#State
Dict-backed state that supports both attribute and dict access.
state.key, state["key"], and state.get("key") all work. Attribute assignment (state.key = val) also works.
#get
def get(self, key: str, default: Any=None) -> Any#Request
Wraps ASGI scope with parsed body and params.
#json
def json(self) -> dict | list | NoneLazily decode the JSON body on first access, then cache.
#body
def body(self) -> bytes | NoneRaw request body bytes.
#query
def query(self, name: str, default: Any=_MISSING, *, type_: type=str, ge: int | float | None=None, le: int | float | None=None, min_length: int | None=None, max_length: int | None=None) -> AnyGet a query parameter by name, with optional type conversion and constraints.
The default is only used when the key is absent from the query string. When no default is given and the key is absent, returns None.
Type coercion failure (key present but unconvertible) always raises HTTPError(422) -- the default is not used as a fallback for bad input.
Constraints (checked after type coercion):
ge: value must be >= this (numeric)le: value must be <= this (numeric)min_length: len(value) must be >= this (strings)max_length: len(value) must be <= this (strings)
Raises HTTPError(422) on coercion failure or constraint violation.
#query_list
def query_list(self, name: str, type_: type=str) -> listReturn all values for a multi-value query key with optional type coercion.
Returns an empty list if the key is absent. Raises HTTPError(422) if any value cannot be converted to type_.
#query_params
def query_params(self) -> dict[str, str]Parsed query string as a dict (first value per key). Cached.
#header
def header(self, name: str, default: str | None=None) -> str | NoneReturn a request header by name (case-insensitive).
ASGI headers arrive as a list of (bytes, bytes) tuples. This helper decodes both to str and looks the name up case-insensitively, matching HTTP semantics.
#body_size
def body_size(self) -> intLength in bytes of the raw request body (0 if no body).
#state
def state(self) -> StateLifespan + per-request state, supporting both attribute and dict access. Cached.
#method
def method(self) -> strHTTP method (GET, POST, etc.).
#path
def path(self) -> strRequest path.
#is_disconnected
async def is_disconnected(self) -> boolCheck whether the client has disconnected.
#cookies
def cookies(self) -> dict[str, str]Parse Cookie header and return a dict of cookie name-value pairs.
#cookie
def cookie(self, name: str, default: str | None=None) -> str | NoneGet a single cookie value by name.
#json_as
def json_as(self, model: type)Parse request body as a Pydantic model. Raises HTTPError(422) on failure.