Crate armature_http_client

Crate armature_http_client 

Source
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§

header
HTTP header types
prelude
Prelude for common imports.

Structs§

Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
CircuitBreaker
Circuit breaker implementation.
CircuitBreakerConfig
Circuit breaker configuration.
HeaderMap
A specialized multimap for header names and values.
HeaderValue
Represents an HTTP header field value.
HttpClient
HTTP client with retry, circuit breaker, and timeout support.
HttpClientConfig
HTTP client configuration.
HttpClientConfigBuilder
Builder for HTTP client configuration.
Method
The Request Method (VERB)
MiddlewareChain
Chain of middleware handlers.
RequestBuilder
HTTP request builder.
Response
HTTP response wrapper.
RetryConfig
Retry configuration.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Url
A parsed URL record.

Enums§

BackoffStrategy
Backoff strategy for retries.
CircuitState
Circuit breaker state.
HttpClientError
HTTP client errors.

Traits§

Interceptor
Interceptor trait for modifying requests and responses.
Middleware
Middleware trait for processing requests and responses.
RequestInterceptor
Request-only interceptor.
ResponseInterceptor
Response-only interceptor.
RetryStrategy
Retry strategy trait for custom retry logic.

Type Aliases§

Result
Result type for HTTP client operations.