use reqwest::{Client, Method};
#[derive(Clone)]
pub struct ApiClient {
base_url: String,
client: Client,
}
impl ApiClient {
pub fn new(base_url: String) -> Self {
Self {
base_url,
client: Client::new(),
}
}
pub async fn send_request(
&self,
method: Method,
path: &str,
body: Option<serde_json::Value>,
) -> Result<serde_json::Value, reqwest::Error> {
let url = format!("{}/{}", self.base_url, path);
let mut request = self.client.request(method, &url);
if let Some(body) = body {
request = request.json(&body);
}
let response = request.send().await?;
response.json::<serde_json::Value>().await
}
}