tower-reqwest

Crates.iotower-reqwest
lib.rstower-reqwest
version
sourcesrc
created_at2024-04-19 09:47:22.631435
updated_at2024-12-04 11:26:46.008372
descriptionAdapter between reqwest and tower-http crates.
homepage
repositoryhttps://github.com/alekseysidorov/tower-http-client
max_upload_size
id1213449
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Aleksey Sidorov (alekseysidorov)

documentation

https://docs.rs/crate/tower-reqwest

README

tower-reqwest

tests crates.io Documentation MIT/Apache-2 licensed

This library provides adapters to use reqwest client with the tower_http layers.

Example

use http::{header::USER_AGENT, HeaderValue};
use http_body_util::BodyExt;
use serde_json::Value;
use tower::{ServiceBuilder, Service};
use tower_http::ServiceBuilderExt;
use tower_reqwest::HttpClientLayer;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = ServiceBuilder::new()
        // Add some layers.
        .override_request_header(USER_AGENT, HeaderValue::from_static("tower-reqwest"))
        // Make client compatible with the `tower-http` layers.
        .layer(HttpClientLayer)
        .service(reqwest::Client::new());
    // Execute request by using this service.
    let response = client
        .call(
            http::request::Builder::new()
                .method(http::Method::GET)
                .uri("http://ip.jsontest.com")
                .body(reqwest::Body::default())?,
        )
        .await?;

    let bytes = response.into_body().collect().await?.to_bytes();
    let value: Value = serde_json::from_slice(&bytes)?;
    println!("{value:#?}");

    Ok(())
}
Commit count: 106

cargo fmt