use reqwest::Client;
use serde::Serialize;
pub struct HttpClient {
inner: Client,
}
impl HttpClient {
pub fn new() -> Self {
let inner = Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()
.expect("failed to initialise reqwest client — TLS backend unavailable");
Self { inner }
}
pub fn with_reqwest(client: Client) -> Self {
Self { inner: client }
}
pub async fn post_json(
&self,
url: &str,
body: &impl Serialize,
) -> Result<reqwest::Response, reqwest::Error> {
self.inner.post(url).json(body).send().await
}
pub fn inner(&self) -> &Client {
&self.inner
}
}
impl Default for HttpClient {
fn default() -> Self {
Self::new()
}
}