Crate tower_http_client

source ·
Expand description


This library provides middlewares and various utilities for HTTP-clients.

Thus, it extends the tower_http functionality for creating HTTP clients using tower middlewares.

At the moment, the de facto standard client library is reqwest, which is poorly compatible with the tower services, but thanks to the tower_reqwest crate, it can be used with the any tower_http layers.

The first goal of the project is to create a more flexible and extensible alternative for reqwest_middleware.


This crate is currently in early stage of development and is not ready for production use.


use http::{header::USER_AGENT, HeaderValue};
use tower::{ServiceBuilder, ServiceExt};
use tower_http::ServiceBuilderExt;
use tower_http_client::{ServiceExt as _, ResponseExt as _};
use tower_reqwest::HttpClientLayer;

/// Implementation agnostic HTTP client.
type HttpClient = tower::util::BoxCloneService<

/// Creates HTTP client with Tower layers on top of the given client.
fn make_client(client: reqwest::Client) -> HttpClient {
        // Add some layers.
        .override_request_header(USER_AGENT, HeaderValue::from_static("tower-http-client"))
        // Make client compatible with the `tower-http` layers.

async fn main() -> anyhow::Result<()> {
    // Create a new client
    let client = make_client(reqwest::Client::new());
    // Execute request by using this service.
    let response = client

    let text = response.body_reader().utf8().await?;



  • adaptersreqwest
    Adapters for various clients.
  • Convenient wrapper for reading Body content.
  • Useful utilities for constructing HTTP requests.


Type Aliases§

  • Alias for a type-erased error type.