client_util/
client.rs

1//! This module contains the client implementations for the various HTTP clients.
2//!
3//! A client must be a (`Service`)[`tower_service::Service`]
4//! that receives a [`http::Request<ClientBody>`] and returns a [`http::Response`].
5//!
6//! This crate provides a default client implementation using [`hyper`].
7//!
8//! However, you can use any service as a client, and add more layer upon it.
9#[cfg(feature = "client-hyper")]
10#[cfg_attr(docsrs, doc(cfg(feature = "client-hyper")))]
11pub mod hyper;
12use crate::error::BoxError as BodyError;
13use bytes::Bytes;
14use http_body_util::combinators::BoxBody;
15#[cfg(feature = "client-hyper")]
16#[cfg_attr(docsrs, doc(cfg(feature = "client-hyper")))]
17pub use hyper::*;
18
19#[macro_export]
20macro_rules! shared_client {
21    ($v:vis $getter: ident: $maker: ident -> $ClientType: ty) => {
22        $v fn $getter() -> $ClientType {
23            static mut CLIENT: std::sync::OnceLock<$ClientType> = std::sync::OnceLock::new();
24            unsafe {
25                CLIENT.get_or_init($maker).clone()
26            }
27        }
28    };
29}
30
31pub type ClientBody = BoxBody<Bytes, BodyError>;