pub trait HttpClient{
type Error;
// Required methods
fn get(
&mut self,
url: impl AsRef<str>,
) -> Result<&mut Self, ValidationError>;
fn head(
&mut self,
url: impl AsRef<str>,
) -> Result<&mut Self, ValidationError>;
fn post(
&mut self,
url: impl AsRef<str>,
) -> Result<&mut Self, ValidationError>;
fn with_header<S: AsRef<str>>(
&mut self,
name: S,
value: S,
) -> Result<&mut Self, ValidationError>;
fn with_body(&mut self, data: impl Into<Vec<u8>>) -> &mut Self;
fn with_body_json(&mut self, body: Value) -> &mut Self;
fn read_body_from_file(&mut self, path: impl Into<PathBuf>) -> &mut Self;
fn user_agent(
&mut self,
user_agent_string: impl Into<String>,
) -> Result<&mut Self, ValidationError>;
fn send<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn send_keep_headers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, HeaderMap), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
A trait that wraps an HTTP client to send HTTP requests.
Required Associated Types§
Required Methods§
Sourcefn get(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>
fn get(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>
Create an HTTP GET
request to the specified URL.
Sourcefn head(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>
fn head(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>
Create an HTTP HEAD
request to the specified URL.
Sourcefn post(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>
fn post(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>
Create an HTTP POST
request to the specified URL.
Sourcefn with_header<S: AsRef<str>>(
&mut self,
name: S,
value: S,
) -> Result<&mut Self, ValidationError>
fn with_header<S: AsRef<str>>( &mut self, name: S, value: S, ) -> Result<&mut Self, ValidationError>
Add a header to the request.
To add a User-Agent
header, call user_agent.
Sourcefn with_body(&mut self, data: impl Into<Vec<u8>>) -> &mut Self
fn with_body(&mut self, data: impl Into<Vec<u8>>) -> &mut Self
Use the provided bytes as the request body.
Sourcefn with_body_json(&mut self, body: Value) -> &mut Self
fn with_body_json(&mut self, body: Value) -> &mut Self
Use the given serde_json::Value as the request’s body.
Sourcefn read_body_from_file(&mut self, path: impl Into<PathBuf>) -> &mut Self
fn read_body_from_file(&mut self, path: impl Into<PathBuf>) -> &mut Self
Read the provided path as the request’s body.
Sourcefn user_agent(
&mut self,
user_agent_string: impl Into<String>,
) -> Result<&mut Self, ValidationError>
fn user_agent( &mut self, user_agent_string: impl Into<String>, ) -> Result<&mut Self, ValidationError>
Set the User-Agent header value to send with requests.
Sourcefn send<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Send the previously-constructed request and return a response.
Sourcefn send_keep_headers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, HeaderMap), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send_keep_headers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, HeaderMap), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Send the previously-constructed request and return a response with the returned HTTP headers.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.