Start fetching events

This commit is contained in:
Dominik Werder
2021-07-09 21:34:03 +02:00
parent e17edd0533
commit 09724fd540
13 changed files with 412 additions and 86 deletions

27
httpclient/src/lib.rs Normal file
View File

@@ -0,0 +1,27 @@
use err::Error;
use hyper::{Body, Method};
use netpod::{AppendToUrl, ChannelConfigQuery, ChannelConfigResponse, NodeConfigCached};
use url::Url;
pub async fn get_channel_config(
q: &ChannelConfigQuery,
node_config: &NodeConfigCached,
) -> Result<ChannelConfigResponse, Error> {
let mut url = Url::parse(&format!(
"http://{}:{}/api/4/channel/config",
"localhost", node_config.node.port
))?;
q.append_to_url(&mut url);
let req = hyper::Request::builder()
.method(Method::GET)
.uri(url.as_str())
.body(Body::empty())?;
let client = hyper::Client::new();
let res = client.request(req).await?;
if !res.status().is_success() {
return Err(Error::with_msg("http client error"));
}
let buf = hyper::body::to_bytes(res.into_body()).await?;
let ret: ChannelConfigResponse = serde_json::from_slice(&buf)?;
Ok(ret)
}