pub struct HttpClient { /* private fields */ }Expand description
HTTP client with retry and rate limiting support
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(config: HttpConfig) -> Result<Self>
pub fn new(config: HttpConfig) -> Result<Self>
Sourcepub fn new_with_rate_limiter(
config: HttpConfig,
rate_limiter: RateLimiter,
) -> Result<Self>
pub fn new_with_rate_limiter( config: HttpConfig, rate_limiter: RateLimiter, ) -> Result<Self>
Sourcepub fn set_rate_limiter(&mut self, rate_limiter: RateLimiter)
pub fn set_rate_limiter(&mut self, rate_limiter: RateLimiter)
Sourcepub fn set_retry_strategy(&mut self, strategy: RetryStrategy)
pub fn set_retry_strategy(&mut self, strategy: RetryStrategy)
Sets the retry strategy for this client.
§Arguments
strategy- Retry strategy to use for failed requests
Sourcepub fn set_circuit_breaker(&mut self, circuit_breaker: Arc<CircuitBreaker>)
pub fn set_circuit_breaker(&mut self, circuit_breaker: Arc<CircuitBreaker>)
Sets the circuit breaker for this client.
§Arguments
circuit_breaker- Circuit breaker instance to use
§Example
use ccxt_core::http_client::{HttpClient, HttpConfig};
use ccxt_core::circuit_breaker::{CircuitBreaker, CircuitBreakerConfig};
use std::sync::Arc;
let mut client = HttpClient::new(HttpConfig::default()).unwrap();
let cb = Arc::new(CircuitBreaker::new(CircuitBreakerConfig::default()));
client.set_circuit_breaker(cb);Sourcepub fn circuit_breaker(&self) -> Option<&Arc<CircuitBreaker>>
pub fn circuit_breaker(&self) -> Option<&Arc<CircuitBreaker>>
Returns a reference to the circuit breaker, if configured.
This can be used to check the circuit breaker state or manually record success/failure.
Sourcepub fn config(&self) -> &HttpConfig
pub fn config(&self) -> &HttpConfig
Returns a reference to current HTTP configuration.
Sourcepub fn set_config(&mut self, config: HttpConfig)
pub fn set_config(&mut self, config: HttpConfig)
Source§impl HttpClient
impl HttpClient
Sourcepub async fn fetch(
&self,
url: &str,
method: Method,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn fetch( &self, url: &str, method: Method, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Executes an HTTP request with automatic retry mechanism and timeout control.
The entire retry flow is wrapped with tokio::time::timeout to ensure
that the total operation time (including all retries) does not exceed
the configured timeout.
§Arguments
url- Target URL for the requestmethod- HTTP method to useheaders- Optional custom headersbody- Optional request body as JSON
§Returns
Returns the response body as a JSON Value.
§Errors
Returns an error if:
- The operation times out (including all retries)
- All retry attempts fail
- The server returns an error status code
- Network communication fails
Sourcepub async fn post(
&self,
url: &str,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn post( &self, url: &str, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Sourcepub async fn put(
&self,
url: &str,
headers: Option<HeaderMap>,
body: Option<Value>,
) -> Result<Value>
pub async fn put( &self, url: &str, headers: Option<HeaderMap>, body: Option<Value>, ) -> Result<Value>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl !UnwindSafe for HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more