Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient
where Self: Default + Clone + Sized,
{ 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§

Source

type Error

The HTTP client’s Error type.

Required Methods§

Source

fn get(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>

Create an HTTP GET request to the specified URL.

Source

fn head(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>

Create an HTTP HEAD request to the specified URL.

Source

fn post(&mut self, url: impl AsRef<str>) -> Result<&mut Self, ValidationError>

Create an HTTP POST request to the specified URL.

Source

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.

Source

fn with_body(&mut self, data: impl Into<Vec<u8>>) -> &mut Self

Use the provided bytes as the request body.

Source

fn with_body_json(&mut self, body: Value) -> &mut Self

Use the given serde_json::Value as the request’s body.

Source

fn read_body_from_file(&mut self, path: impl Into<PathBuf>) -> &mut Self

Read the provided path as the request’s body.

Source

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.

Source

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.

Source

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".

Implementors§