reqx 0.1.35

Rust HTTP transport client for API SDK libraries with retry, timeout, idempotency, proxy, and pluggable TLS backends
Documentation
use std::time::Duration;

use reqx::prelude::{Client, Error, RetryPolicy};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::builder("https://postman-echo.com")
        .client_name("reqx-example-error-handling")
        .request_timeout(Duration::from_secs(3))
        .retry_policy(RetryPolicy::disabled())
        .build()?;

    let result = client.get("/status/500").send().await;
    match result {
        Ok(response) => {
            println!("unexpected success: status={}", response.status());
        }
        Err(error) => {
            println!("error_code={}", error.code().as_str());
            match &error {
                Error::HttpStatus { status, body, .. } => {
                    println!("http status error: status={status} body={body}");
                }
                Error::Timeout {
                    phase, timeout_ms, ..
                } => {
                    println!("timeout: phase={phase} timeout_ms={timeout_ms}");
                }
                Error::Transport { kind, .. } => {
                    println!("transport error kind={kind}");
                }
                other => {
                    println!("other error: {other}");
                }
            }
        }
    }

    Ok(())
}