bocadillo.request

Request

Request(self, scope:MutableMapping[str, Any], receive:Callable[[], Awaitable[MutableMapping[str, Any]]]=<function empty_receive at 0x7f5b6b20c2f0>)

The request object, passed to HTTP views and typically named req.

This is a subclass of Starlette.requests.Request. As a result, all methods and attributes on Starlette's Request are available on this class. Additional or redefined members are documented here.

For usage tips, see Requests (Guide).

Methods

__aiter__: shortcut for .stream(). Allows to process the request body in byte chunks using async for chunk in req: ....

json

Request.json(self) -> Any

Parse the request body as JSON.

Returns

json (dict): the result of json.loads(await self.body()).

Raises

  • HTTPError(400): if the JSON is malformed.