1use super::*;
3use reqwest;
4#[derive(Debug, Clone)]
9pub struct Client {
10 client: reqwest::Client,
11 service_uri: String,
12}
13
14impl Client {
15 pub fn connect(address: impl std::fmt::Display) -> Self {
17 let client = reqwest::Client::builder().build().expect("reqwest client");
19 let service_uri = format!("http://{}", address);
20 Self { client, service_uri }
21 }
22}
23impl Client {
27 pub(crate) async fn post(&self, end_point: &str, data: impl serde::Serialize) -> Result<String> {
29 trace!("post to {end_point:?}");
30 let uri = format!("{}/{end_point}", self.service_uri);
31 let resp = self.client.post(&uri).json(&data).send().await?.text().await?;
32 Ok(resp)
33 }
34}
35