Expand description
§Armature HTTP Client
A robust HTTP client with built-in retry logic, circuit breaker pattern, timeout management, and request/response interceptors.
§Features
- Retry with Backoff: Configurable retry strategies (exponential, linear, constant)
- Circuit Breaker: Prevents cascade failures with automatic recovery
- Timeouts: Per-request and global timeout configuration
- Interceptors: Request/response transformation and logging
- Connection Pooling: Efficient connection reuse
- Compression: Automatic gzip/brotli support
§Quick Start
use armature_http_client::{HttpClient, HttpClientConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HttpClient::new(HttpClientConfig::default());
let response = client
.get("https://api.example.com/users")
.send()
.await?;
println!("Status: {}", response.status());
Ok(())
}§With Retry and Circuit Breaker
use armature_http_client::{HttpClient, HttpClientConfig, RetryConfig, CircuitBreakerConfig};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = HttpClientConfig::builder()
.timeout(Duration::from_secs(30))
.retry(RetryConfig::exponential(3, Duration::from_millis(100)))
.circuit_breaker(CircuitBreakerConfig::default())
.build();
let client = HttpClient::new(config);
// Requests will automatically retry on failure
// Circuit breaker will open after consecutive failures
let response = client
.post("https://api.example.com/orders")
.json(&serde_json::json!({"item": "widget", "quantity": 5}))
.send()
.await?;
Ok(())
}Modules§
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Circuit
Breaker - Circuit breaker implementation.
- Circuit
Breaker Config - Circuit breaker configuration.
- Header
Map - A specialized multimap for header names and values.
- Header
Value - Represents an HTTP header field value.
- Http
Client - HTTP client with retry, circuit breaker, and timeout support.
- Http
Client Config - HTTP client configuration.
- Http
Client Config Builder - Builder for HTTP client configuration.
- Method
- The Request Method (VERB)
- Middleware
Chain - Chain of middleware handlers.
- Request
Builder - HTTP request builder.
- Response
- HTTP response wrapper.
- Retry
Config - Retry configuration.
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Url
- A parsed URL record.
Enums§
- Backoff
Strategy - Backoff strategy for retries.
- Circuit
State - Circuit breaker state.
- Http
Client Error - HTTP client errors.
Traits§
- Interceptor
- Interceptor trait for modifying requests and responses.
- Middleware
- Middleware trait for processing requests and responses.
- Request
Interceptor - Request-only interceptor.
- Response
Interceptor - Response-only interceptor.
- Retry
Strategy - Retry strategy trait for custom retry logic.
Type Aliases§
- Result
- Result type for HTTP client operations.