use super::messaging;
use crate::err;
#[derive(Default, Debug, Clone)]
pub struct Client {
host: String,
}
impl Client {
pub fn new(host: &str) -> Self {
let mut host = host.to_string();
host.push_str("/query");
Self { host }
}
pub async fn execute(&self, request: messaging::Request) -> super::Result<messaging::Response> {
let client = reqwest::Client::default();
let response = client
.post(&self.host)
.json(&request)
.send()
.await
.map_err(|_| err!(client, HTTPRequestFail))?;
let body = response
.json::<messaging::Response>()
.await
.map_err(|_| err!(client, ReadBodyFail))?;
Ok(body)
}
}