pub struct HttpClient { /* private fields */ }
Expand description
HTTP client with various utility methods
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn with_base_url(base_url: impl Into<String>) -> Self
pub fn with_base_url(base_url: impl Into<String>) -> Self
Create a new HTTP client with a base URL
Sourcepub fn with_client(client: Client) -> Self
pub fn with_client(client: Client) -> Self
Create a new HTTP client with a custom reqwest Client
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set a timeout for all requests
Sourcepub async fn get(&self, endpoint: &str) -> Result<Response, HttpClientError>
pub async fn get(&self, endpoint: &str) -> Result<Response, HttpClientError>
Send a GET request
Sourcepub async fn get_with_query<T: Serialize + ?Sized>(
&self,
endpoint: &str,
query: &T,
) -> Result<Response, HttpClientError>
pub async fn get_with_query<T: Serialize + ?Sized>( &self, endpoint: &str, query: &T, ) -> Result<Response, HttpClientError>
Send a GET request with query parameters
Sourcepub async fn post<T: Serialize + ?Sized>(
&self,
endpoint: &str,
body: &T,
) -> Result<Response, HttpClientError>
pub async fn post<T: Serialize + ?Sized>( &self, endpoint: &str, body: &T, ) -> Result<Response, HttpClientError>
Send a POST request with JSON body
Sourcepub async fn post_raw(
&self,
endpoint: &str,
body: Vec<u8>,
content_type: &str,
) -> Result<Response, HttpClientError>
pub async fn post_raw( &self, endpoint: &str, body: Vec<u8>, content_type: &str, ) -> Result<Response, HttpClientError>
Send a POST request with raw bytes
Sourcepub async fn download_file(
&self,
url: &str,
destination: &Path,
progress_callback: impl FnMut(u64, u64),
) -> Result<(), HttpClientError>
pub async fn download_file( &self, url: &str, destination: &Path, progress_callback: impl FnMut(u64, u64), ) -> Result<(), HttpClientError>
Download a file with progress reporting
Sourcepub async fn download_file_with_resume(
&self,
url: &str,
destination: &Path,
progress_callback: impl FnMut(u64, u64),
) -> Result<(), HttpClientError>
pub async fn download_file_with_resume( &self, url: &str, destination: &Path, progress_callback: impl FnMut(u64, u64), ) -> Result<(), HttpClientError>
Download a file with resume support and progress reporting
Sourcepub async fn json<T: DeserializeOwned>(
response: Response,
) -> Result<T, HttpClientError>
pub async fn json<T: DeserializeOwned>( response: Response, ) -> Result<T, HttpClientError>
Parse response as JSON
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for HttpClient
impl Debug for HttpClient
Auto Trait Implementations§
impl Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl !UnwindSafe for HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more