pub struct HttpClient { /* private fields */ }Expand description
Async HTTP client with auth, headers, and error handling.
§Security
TLS certificate verification must never be disabled in production. danger_accept_invalid_certs
is only available behind the danger-tls feature flag and must not be enabled in release builds.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(config: HttpClientConfig) -> AppResult<Self>
pub fn new(config: HttpClientConfig) -> AppResult<Self>
Creates a new HTTP client with the given configuration.
Sourcepub fn from_parts(config: HttpClientConfig, client: Client) -> Self
pub fn from_parts(config: HttpClientConfig, client: Client) -> Self
Wraps an existing reqwest client with canonical configuration metadata.
Sourcepub fn config(&self) -> &HttpClientConfig
pub fn config(&self) -> &HttpClientConfig
Gets the configuration.
Sourcepub async fn get(&self, path: &str) -> AppResult<Response>
pub async fn get(&self, path: &str) -> AppResult<Response>
Executes a GET request and returns the response.
Sourcepub async fn send_checked(&self, req: Request) -> AppResult<Response>
pub async fn send_checked(&self, req: Request) -> AppResult<Response>
Executes a request and converts non-2xx responses into an error.
Sourcepub async fn get_json<T: DeserializeOwned>(&self, path: &str) -> AppResult<T>
pub async fn get_json<T: DeserializeOwned>(&self, path: &str) -> AppResult<T>
Executes a GET request and parses the response as JSON.
Sourcepub async fn post<T: Serialize>(
&self,
path: &str,
body: &T,
) -> AppResult<Response>
pub async fn post<T: Serialize>( &self, path: &str, body: &T, ) -> AppResult<Response>
Executes a POST request with a JSON body.
Sourcepub async fn post_json<T: Serialize, R: DeserializeOwned>(
&self,
path: &str,
body: &T,
) -> AppResult<R>
pub async fn post_json<T: Serialize, R: DeserializeOwned>( &self, path: &str, body: &T, ) -> AppResult<R>
Executes a POST request with a JSON body and parses the response as JSON.
Sourcepub async fn put<T: Serialize>(
&self,
path: &str,
body: &T,
) -> AppResult<Response>
pub async fn put<T: Serialize>( &self, path: &str, body: &T, ) -> AppResult<Response>
Executes a PUT request with a JSON body.
Sourcepub async fn put_json<T: Serialize, R: DeserializeOwned>(
&self,
path: &str,
body: &T,
) -> AppResult<R>
pub async fn put_json<T: Serialize, R: DeserializeOwned>( &self, path: &str, body: &T, ) -> AppResult<R>
Executes a PUT request with a JSON body and parses the response as JSON.
Sourcepub async fn patch<T: Serialize>(
&self,
path: &str,
body: &T,
) -> AppResult<Response>
pub async fn patch<T: Serialize>( &self, path: &str, body: &T, ) -> AppResult<Response>
Executes a PATCH request with a JSON body.
Sourcepub async fn patch_json<T: Serialize, R: DeserializeOwned>(
&self,
path: &str,
body: &T,
) -> AppResult<R>
pub async fn patch_json<T: Serialize, R: DeserializeOwned>( &self, path: &str, body: &T, ) -> AppResult<R>
Executes a PATCH request with a JSON body and parses the response as JSON.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more