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

22
httpclient/Cargo.toml Normal file
View File

@@ -0,0 +1,22 @@
[package]
name = "httpclient"
version = "0.0.1-a.0"
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
edition = "2018"
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
http = "0.2"
url = "2.2"
tokio = { version = "1.7.1", features = ["rt-multi-thread", "io-util", "net", "time", "sync", "fs"] }
hyper = { version = "0.14", features = ["http1", "http2", "client", "server", "tcp", "stream"] }
hyper-tls = { version="0.5.0" }
bytes = "1.0.1"
futures-core = "0.3.14"
futures-util = "0.3.14"
tracing = "0.1.25"
async-channel = "1.6"
err = { path = "../err" }
netpod = { path = "../netpod" }
parse = { path = "../parse" }

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)
}