pub struct HttpClient { /* private fields */ }Expand description
A thin wrapper around reqwest::Client shared by all hooksmith service crates.
Service crates (e.g. discord_hook, slack_hook) hold one of these,
configure it at construction time, and call HttpClient::post_json to
fire requests.
TLS configuration is the responsibility of the service crate — build a
reqwest::Client with your chosen TLS backend and pass it in via
HttpClient::with_reqwest.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a client backed by a freshly-constructed reqwest::Client.
A 30-second request timeout is applied by default so that a slow or
unresponsive endpoint can never hang your application indefinitely.
Override this by building your own reqwest::Client and passing it
to HttpClient::with_reqwest.
Sourcepub fn with_reqwest(client: Client) -> Self
pub fn with_reqwest(client: Client) -> Self
Wrap an existing reqwest::Client.
Use this to share a connection pool or inject custom configuration (timeouts, proxies, etc.) across your application.
Sourcepub async fn post_json(
&self,
url: &str,
body: &impl Serialize,
) -> Result<Response, Error>
pub async fn post_json( &self, url: &str, body: &impl Serialize, ) -> Result<Response, Error>
POST body serialized as JSON to url and return the raw response.
Sourcepub fn inner(&self) -> &Client
pub fn inner(&self) -> &Client
Access the underlying reqwest::Client for advanced use-cases.