feat(client): provide tower::Service support for clients (#1915)
This commit is contained in:
committed by
Sean McArthur
parent
eef407d60e
commit
eee2a72879
26
examples/tower_client.rs
Normal file
26
examples/tower_client.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user