Trait b2_client::client::HttpClient
source · [−]pub trait HttpClient where
Self: Default + Clone + Sized, {
type Error;
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
'life0: 'async_trait,
Self: '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
'life0: 'async_trait,
Self: 'async_trait;
}Expand description
A trait that wraps an HTTP client to send HTTP requests.
Associated Types
Required methods
Create an HTTP GET request to the specified URL.
Create an HTTP HEAD request to the specified URL.
Create an HTTP POST request to the specified URL.
fn 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.
Use the provided bytes as the request body.
fn 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.
fn 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.
fn 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.
Send the previously-constructed request and return a response.
Send the previously-constructed request and return a response with the returned HTTP headers.