forked from hyperium/tonic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.rs
More file actions
29 lines (21 loc) · 811 Bytes
/
client.rs
File metadata and controls
29 lines (21 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use hello_world::{greeter_client::GreeterClient, HelloRequest};
use hyper_util::rt::TokioExecutor;
use tonic_web::GrpcWebClientLayer;
pub mod hello_world {
tonic::include_proto!("helloworld");
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Must use hyper directly...
let client = hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build_http();
let svc = tower::ServiceBuilder::new()
.layer(GrpcWebClientLayer::new())
.service(client);
let mut client = GreeterClient::with_origin(svc, "http://127.0.0.1:3000".try_into()?);
let request = tonic::Request::new(HelloRequest {
name: "Tonic".into(),
});
let response = client.say_hello(request).await?;
println!("RESPONSE={response:?}");
Ok(())
}