Skip to content

http

Async HTTP request client implementation built on httpx.

Client

Base class for HTTP clients.

client = Client()
response = await client.request("GET", "/some/resource")
assert response.status_code == 200

close classmethod async

close()

Closes the underlying client transport and proxies.

json

json(response)

Abstracts deserializing to allow for optional unwrapping of server response, e.g., {"data": []}.

Parameters
httpx.Response

Response object, we call .json() on it.

Returns

Any The result of httpx.Response.json() after passing through self.unwrap_json().

request async

request(*args, **kwargs)

Passes *args, **kwargs straight through to httpx.AsyncClient.request, we call raise_for_status() on the response and wrap any HTTPX error in a ClientException.

Parameters

args : Any Unpacked into httpx.AsyncClient.request(). *kwargs : Any Unpacked into httpx.AsyncClient.request().

Returns

httpx.Response Return value of httpx.AsyncClient.request() after calling httpx.Response.raise_for_status()

Raises

ClientException Wraps any httpx.HTTPError arising from the request or response status check.

unwrap_json staticmethod

unwrap_json(data)

Overwrite this method for pre-processing response data, for example unwrapping enveloped data.

Parameters
Any

Value returned from response.json().

Returns

Any Pre-processed data, default is pass-through/no-op.

ClientException

Bases: Exception

Base client exception.