Skip to main content

Crate reqsign_http_send_reqwest

Crate reqsign_http_send_reqwest 

Source
Expand description

Reqwest-based HTTP client implementation for reqsign.

This crate provides ReqwestHttpSend, an HTTP client that implements the HttpSend trait from reqsign_core using the popular reqwest library.

§Overview

ReqwestHttpSend enables reqsign to send HTTP requests using reqwest’s powerful and feature-rich HTTP client. It handles the conversion between standard http types and reqwest’s types seamlessly.

§Example

use reqsign_core::Context;
use reqsign_http_send_reqwest::ReqwestHttpSend;
use reqwest::Client;

#[tokio::main]
async fn main() {
    // Use default client
    let ctx = Context::new()
        .with_http_send(ReqwestHttpSend::default());

    // Or use a custom configured client
    let client = Client::builder()
        .timeout(std::time::Duration::from_secs(30))
        .build()
        .unwrap();

    let ctx = Context::new()
        .with_http_send(ReqwestHttpSend::new(client));
}

§Usage with Service Signers

use reqsign_core::{Context, Signer};
use reqsign_http_send_reqwest::ReqwestHttpSend;
use bytes::Bytes;

// Create context with reqwest HTTP client
let ctx = Context::new()
    .with_http_send(ReqwestHttpSend::default());

// The context can send HTTP requests
let req = http::Request::builder()
    .method("GET")
    .uri("https://api.example.com")
    .body(Bytes::new())?;

let resp = ctx.http_send(req).await?;
println!("Response status: {}", resp.status());

§Custom Client Configuration

use reqsign_http_send_reqwest::ReqwestHttpSend;
use reqwest::Client;
use std::time::Duration;

// Configure reqwest client with custom settings
let client = Client::builder()
    .timeout(Duration::from_secs(60))
    .pool_max_idle_per_host(10)
    .user_agent("my-app/1.0")
    .build()
    .unwrap();

// Use the custom client
let http_send = ReqwestHttpSend::new(client);

Structs§

ReqwestHttpSend
Reqwest-based implementation of the HttpSend trait.