Request Class¶
The Request
class provides access to HTTP request data including headers, body, and path parameters.
Request ¶
HTTP request object providing access to request data.
This class encapsulates the ASGI scope and receive callable to provide a convenient interface for accessing request data including headers, body content, and path parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scope
|
dict[str, Any]
|
ASGI scope dictionary containing request metadata |
required |
receive
|
Callable[[], Awaitable[dict[str, Any]]]
|
ASGI receive callable for getting request body |
required |
Attributes:
Name | Type | Description |
---|---|---|
scope |
The ASGI scope dictionary |
|
receive |
The ASGI receive callable |
|
path_params |
dict[str, str]
|
Dictionary of extracted path parameters |
headers |
dict[str, str]
|
Dictionary of request headers |
Source code in src/artanis/request.py
Functions¶
body
async
¶
Get the request body as bytes.
Reads and caches the complete request body from the ASGI receive callable. The body is cached after the first call to avoid multiple reads.
Returns:
Type | Description |
---|---|
bytes
|
The complete request body as bytes |
Source code in src/artanis/request.py
json
async
¶
Parse request body as JSON.
Reads the request body and parses it as JSON data.
Returns:
Type | Description |
---|---|
Any
|
Parsed JSON data (dict, list, or other JSON-serializable types) |
Raises:
Type | Description |
---|---|
ValidationError
|
If the body is not valid JSON |