feat(client): provide tower::Service support for clients (#1915)

This commit is contained in:
Lucio Franco
2019-08-30 15:54:22 -04:00
committed by Sean McArthur
parent eef407d60e
commit eee2a72879
6 changed files with 184 additions and 9 deletions

26
examples/tower_client.rs Normal file
View File

@@ -0,0 +1,26 @@
use hyper::client::service::{Connect, Service, MakeService};
use hyper::client::conn::Builder;
use hyper::client::connect::HttpConnector;
use hyper::{Body, Request};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
pretty_env_logger::init();
let mut mk_svc = Connect::new(HttpConnector::new(), Builder::new());
let uri = "http://127.0.0.1:8080".parse::<http::Uri>()?;
let mut svc = mk_svc.make_service(uri.clone()).await?;
let body = Body::empty();
let req = Request::get(uri).body(body)?;
let res = svc.call(req).await?;
println!("RESPONSE={:?}", res);
Ok(())
}