pub struct HttpClient { /* private fields */ }
Expand description
HTTP client for making requests to the Replicate API with retry logic.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(api_token: impl Into<String>) -> Result<Self>
pub fn new(api_token: impl Into<String>) -> Result<Self>
Create a new HTTP client with the given API token and default retry logic.
Sourcepub fn with_retry_config(
api_token: impl Into<String>,
retry_config: RetryConfig,
) -> Result<Self>
pub fn with_retry_config( api_token: impl Into<String>, retry_config: RetryConfig, ) -> Result<Self>
Create a new HTTP client with the given API token and custom retry configuration.
Sourcepub fn with_http_config(
api_token: impl Into<String>,
http_config: HttpConfig,
) -> Result<Self>
pub fn with_http_config( api_token: impl Into<String>, http_config: HttpConfig, ) -> Result<Self>
Create a new HTTP client with the given API token and custom HTTP configuration.
Sourcepub fn with_base_url(
api_token: impl Into<String>,
base_url: impl Into<String>,
) -> Result<Self>
pub fn with_base_url( api_token: impl Into<String>, base_url: impl Into<String>, ) -> Result<Self>
Create a new HTTP client with custom base URL.
Sourcepub fn with_base_url_and_retry(
api_token: impl Into<String>,
base_url: impl Into<String>,
retry_config: RetryConfig,
) -> Result<Self>
pub fn with_base_url_and_retry( api_token: impl Into<String>, base_url: impl Into<String>, retry_config: RetryConfig, ) -> Result<Self>
Create a new HTTP client with custom base URL and retry configuration.
Sourcepub fn with_base_url_and_http_config(
api_token: impl Into<String>,
base_url: impl Into<String>,
http_config: HttpConfig,
) -> Result<Self>
pub fn with_base_url_and_http_config( api_token: impl Into<String>, base_url: impl Into<String>, http_config: HttpConfig, ) -> Result<Self>
Create a new HTTP client with custom base URL and HTTP configuration.
Sourcepub fn inner(&self) -> &ClientWithMiddleware
pub fn inner(&self) -> &ClientWithMiddleware
Get a reference to the underlying client with middleware.
Sourcepub async fn post<T: Serialize>(&self, path: &str, body: &T) -> Result<Response>
pub async fn post<T: Serialize>(&self, path: &str, body: &T) -> Result<Response>
Make a POST request with JSON body.
Sourcepub async fn post_empty(&self, path: &str) -> Result<Response>
pub async fn post_empty(&self, path: &str) -> Result<Response>
Make a POST request without a body.
Sourcepub async fn put<T: Serialize>(&self, path: &str, body: &T) -> Result<Response>
pub async fn put<T: Serialize>(&self, path: &str, body: &T) -> Result<Response>
Make a PUT request with JSON body.
Sourcepub async fn get_json<T: for<'de> Deserialize<'de>>(
&self,
path: &str,
) -> Result<T>
pub async fn get_json<T: for<'de> Deserialize<'de>>( &self, path: &str, ) -> Result<T>
Make a GET request and deserialize the response as JSON.
Sourcepub async fn post_json<B: Serialize, T: for<'de> Deserialize<'de>>(
&self,
path: &str,
body: &B,
) -> Result<T>
pub async fn post_json<B: Serialize, T: for<'de> Deserialize<'de>>( &self, path: &str, body: &B, ) -> Result<T>
Make a POST request and deserialize the response as JSON.
Sourcepub async fn post_empty_json<T: for<'de> Deserialize<'de>>(
&self,
path: &str,
) -> Result<T>
pub async fn post_empty_json<T: for<'de> Deserialize<'de>>( &self, path: &str, ) -> Result<T>
Make a POST request without body and deserialize the response as JSON.
Sourcepub fn configure_retries(
&mut self,
max_retries: u32,
min_delay: Duration,
max_delay: Duration,
) -> Result<()>
pub fn configure_retries( &mut self, max_retries: u32, min_delay: Duration, max_delay: Duration, ) -> Result<()>
Configure retry policy for this client.
This rebuilds the underlying HTTP client with new retry settings.
§Examples
let mut client = Client::new("your-api-token")?;
// Configure more aggressive retry settings
client.http_client_mut().configure_retries(
5, // max_retries
Duration::from_millis(100), // min_delay
Duration::from_secs(60), // max_delay
)?;
Sourcepub fn configure_retries_advanced(
&mut self,
max_retries: u32,
min_delay: Duration,
max_delay: Duration,
base_multiplier: u32,
) -> Result<()>
pub fn configure_retries_advanced( &mut self, max_retries: u32, min_delay: Duration, max_delay: Duration, base_multiplier: u32, ) -> Result<()>
Configure retry policy with advanced settings.
This rebuilds the underlying HTTP client with new retry settings.
§Arguments
max_retries
- Maximum number of retry attemptsmin_delay
- Minimum delay between retriesmax_delay
- Maximum delay between retriesbase_multiplier
- Base multiplier for exponential backoff (typically 2)
Sourcepub fn configure_timeouts(
&mut self,
connect_timeout: Option<Duration>,
request_timeout: Option<Duration>,
) -> Result<()>
pub fn configure_timeouts( &mut self, connect_timeout: Option<Duration>, request_timeout: Option<Duration>, ) -> Result<()>
Configure timeout settings for this client.
This rebuilds the underlying HTTP client with new timeout settings.
§Arguments
connect_timeout
- Maximum time to wait for connection establishment (None = no timeout)request_timeout
- Maximum time to wait for complete request (None = no timeout)
Sourcepub fn retry_config(&self) -> &RetryConfig
pub fn retry_config(&self) -> &RetryConfig
Get the current retry configuration.
Sourcepub fn timeout_config(&self) -> &TimeoutConfig
pub fn timeout_config(&self) -> &TimeoutConfig
Get the current timeout configuration.
Sourcepub fn http_config(&self) -> &HttpConfig
pub fn http_config(&self) -> &HttpConfig
Get the current HTTP configuration.
Sourcepub async fn post_multipart(&self, path: &str, form: Form) -> Result<Response>
pub async fn post_multipart(&self, path: &str, form: Form) -> Result<Response>
POST request with multipart form data.
Sourcepub async fn post_multipart_json<T: for<'de> Deserialize<'de>>(
&self,
path: &str,
form: Form,
) -> Result<T>
pub async fn post_multipart_json<T: for<'de> Deserialize<'de>>( &self, path: &str, form: Form, ) -> Result<T>
POST multipart form data and parse JSON response.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more