use async_trait::async_trait;
use reqwest::header::{HeaderName, HeaderValue};
use reqwest::{IntoUrl, Method, Request, Response};
#[async_trait]
pub trait RequestBuilder {
type Error: std::error::Error + Send + Sync + 'static;
fn header<K, V>(self, key: K, value: V) -> Self
where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<http::Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<http::Error>;
fn headers(self, headers: reqwest::header::HeaderMap) -> Self;
fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Self
where
U: std::fmt::Display,
P: std::fmt::Display;
fn bearer_auth<T>(self, token: T) -> Self
where
T: std::fmt::Display;
fn body<T: Into<reqwest::Body>>(self, body: T) -> Self;
fn json<T: serde::Serialize + ?Sized>(self, json: &T) -> Self;
fn timeout(self, timeout: std::time::Duration) -> Self;
fn query<T: serde::Serialize + ?Sized>(self, query: &T) -> Self;
fn version(self, version: http::Version) -> Self;
fn build(self) -> Result<Request, reqwest::Error>;
async fn send(self) -> Result<reqwest::Response, Self::Error>;
}
#[async_trait]
pub trait Client {
type RequestBuilder: RequestBuilder;
type Error: std::error::Error + Send + Sync + 'static;
fn get<U: IntoUrl>(&self, url: U) -> Self::RequestBuilder;
fn post<U: IntoUrl>(&self, url: U) -> Self::RequestBuilder;
fn put<U: IntoUrl>(&self, url: U) -> Self::RequestBuilder;
fn patch<U: IntoUrl>(&self, url: U) -> Self::RequestBuilder;
fn delete<U: IntoUrl>(&self, url: U) -> Self::RequestBuilder;
fn head<U: IntoUrl>(&self, url: U) -> Self::RequestBuilder;
fn request<U: IntoUrl>(&self, method: Method, url: U) -> Self::RequestBuilder;
async fn execute(&self, request: Request) -> Result<Response, Self::Error>;
}
#[cfg(feature = "reqwest")]
mod impl_reqwest;
pub use impl_reqwest::*;
#[cfg(feature = "reqwest-middleware")]
mod impl_reqwest_middleware;
pub use impl_reqwest_middleware::*;