http
Async HTTP request client implementation built on httpx
.
clients
module-attribute
¶
For bookkeeping of clients.
We close them on app shutdown.
Client ¶
A simple HTTP client class with retrying and exponential backoff.
This class uses the tenacity
library to retry failed HTTP httpx
with exponential backoff and jitter. It also uses a httpx.Session
instance to manage HTTP connections and cookies.
headers: Headers that are applied to every request
delete
async
¶
Make an HTTP DELETE request with retrying and exponential backoff.
This method is a convenience wrapper around the request
method that
sends an HTTP DELETE request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The URL path (e.g. "/users/123") |
required |
headers |
dict[str, str] | None
|
HTTP headers to send with the request (optional) |
None
|
Returns:
Type | Description |
---|---|
httpx.Response
|
The |
Raises:
Type | Description |
---|---|
httpx.RequestException
|
If the request fails and cannot be retried. |
get
async
¶
Make an HTTP GET request with retrying and exponential backoff.
This method is a convenience wrapper around the request
method that
sends an HTTP GET request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The URL path (e.g. "/users/123") |
required |
params |
dict[str, Any] | None
|
Query parameters (optional) |
None
|
headers |
dict[str, str] | None
|
HTTP headers to send with the request (optional) |
None
|
Returns:
Type | Description |
---|---|
httpx.Response
|
The |
Raises:
Type | Description |
---|---|
httpx.RequestException
|
If the request fails and cannot be retried. |
post
async
¶
Make an HTTP POST request with retrying and exponential backoff.
This method is a convenience wrapper around the request
method that
sends an HTTP POST request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The URL path (e.g. "/users/123") |
required |
content |
bytes | None
|
Data to send in the request body (optional) |
None
|
headers |
dict[str, str] | None
|
HTTP headers to send with the request (optional) |
None
|
Returns:
Type | Description |
---|---|
httpx.Response
|
The |
Raises:
Type | Description |
---|---|
httpx.RequestException
|
If the request fails and cannot be retried. |
put
async
¶
Make an HTTP PUT request with retrying and exponential backoff.
This method is a convenience wrapper around the request
method that
sends an HTTP PUT request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The URL path (e.g. "/users/123") |
required |
content |
bytes | None
|
Data to send in the request body (optional) |
None
|
headers |
dict[str, str] | None
|
HTTP headers to send with the request (optional) |
None
|
Returns:
Type | Description |
---|---|
httpx.Response
|
The |
Raises:
Type | Description |
---|---|
httpx.RequestException
|
If the request fails and cannot be retried. |
request
async
¶
Make an HTTP request with retrying and exponential backoff.
This method uses the httpx
library to make an HTTP request and
the tenacity
library to retry the request if it fails. It uses
exponential backoff with jitter to wait between retries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method |
str
|
The HTTP method (e.g. "GET", "POST") |
required |
path |
str
|
The URL path (e.g. "/users/123") |
required |
params |
dict[str, Any] | None
|
Query parameters (optional) |
None
|
content |
bytes | None
|
Data to send in the request body (optional) |
None
|
headers |
dict[str, str] | None
|
HTTP headers to send with the request (optional) |
None
|
Returns:
Type | Description |
---|---|
httpx.Response
|
The |
Raises:
Type | Description |
---|---|
httpx.RequestException
|
If the request fails and cannot be retried. |