HTTP Client¶
- class ultra_piston.http_clients.AbstractHTTPClient¶
An abstract base class for HTTP clients used to communicate with external services.
- Attributes:
- driverOptional[str]
- The name of the HTTP driver or implementation used.
- rate_limitOptional[Union[int, float]]
- Ratelimit to set for the dispatched requests.Takes in a integer / float of the amount of delay (in seconds) between each request.Defaults to 1 request per second.
- base_urlOptional[str]
- The base URL for the API endpoint.
- headersOptional[Dict[str, str]]
- Default headers to include with every request.
- _get_rate_limit()¶
Retrieve the configured request rate limit.
- Returns:
- The rate limit value.
- Raises:
ultra_piston.errors.MissingDataError- If no rate limit is set.
- Return type:
- _get_base_url()¶
Retrieve the configured base URL for the API.
- Returns:
- The base URL.
- Raises:
ultra_piston.errors.MissingDataError- If no base URL is set.
- Return type:
- _get_headers()¶
Retrieve the default HTTP headers for requests.
- Returns:
- The request headers.
- Raises:
ultra_piston.errors.MissingDataError- If no headers are set.
- Return type:
- _get_http_payload(endpoint='')¶
Construct the full HTTP payload with URL and headers.
- Parameters:
- endpoint
- The endpoint path to append to the base URL.
- Returns:
- Dictionary containing the full URL and headers.
- Raises:
ultra_piston.errors.MissingDataError- If no base URL or headers are set.
- abstractmethod get(endpoint)¶
Send a synchronous GET request to the given endpoint.
- Parameters:
- endpoint
- The API endpoint to request.
- Returns:
- The server response.
- abstractmethod async get_async(endpoint)¶
Send an asynchronous GET request to the given endpoint.
- Parameters:
- endpoint
- The API endpoint to request.
- Returns:
- The server response.
- abstractmethod post(endpoint, json_data=None)¶
Send a synchronous POST request with optional JSON data.
- Parameters:
- endpoint
- The API endpoint to request.
- json_data
- The JSON payload to send.
- Returns:
- The server response.
- abstractmethod async post_async(endpoint, json_data=None)¶
Send an asynchronous POST request with optional JSON data.
- Parameters:
- endpoint
- The API endpoint to request.
- json_data
- The JSON payload to send.
- Returns:
- The server response.
- abstractmethod delete(endpoint, json_data=None)¶
Send a synchronous DELETE request with optional JSON data.
- Parameters:
- endpoint
- The API endpoint to request.
- json_data
- The JSON payload to send.
- Returns:
- The server response.
- abstractmethod async delete_async(endpoint, json_data=None)¶
Send an asynchronous DELETE request with optional JSON data.
- Parameters:
- endpoint
- The API endpoint to request.
- json_data
- The JSON payload to send.
- Returns:
- The server response