pub struct Client<'a> { /* private fields */ }
Expand description
A websocket-tunneled, browser enabled tonic client.
This client can be used in place of tonic’s
Channel
.
It tunnels the request through a websocket connection to the server that reconstructs them and send them
to their respective handlers.
§Cryptography
This transport implementation does not directly support encryption. It is however possible to encrypt the websocket connection itself. However, client authentication is not possible that way.
§Example
Assuming we have the greeter example in scope, we can instanciate a connection like so:
let client = Client::connect("ws://localhost:8080").await.unwrap();
let mut client = greeter_client::GreeterClient::new(client);
let request = tonic::Request::new(HelloRequest {
name: "WebTonic".into(),
});
let response = client.say_hello(request).await.unwrap().into_inner();
assert_eq!(response.message, "Hello WebTonic!");
Implementations§
Source§impl Client<'static>
impl Client<'static>
Sourcepub async fn connect(uri: &str) -> Result<Self, WebTonicError>
pub async fn connect(uri: &str) -> Result<Self, WebTonicError>
Connects the client to the endpoint.
§Arguments
uri
: The uri to connect to. Note: The sceme is eitherws://
orwss://
, depending wether encryption is used or not.
§Returns
- A
Client
on success. WebTonicError::InvalidUrl
, if the url is malformed.WebTonicError::ConnectionError
, if the endpoint can not be reached.
§Example
let client = Client::connect("ws://localhost:1337").await.unwrap();
Trait Implementations§
Source§impl<'a> GrpcService<BoxBody> for Client<'a>
impl<'a> GrpcService<BoxBody> for Client<'a>
Source§type ResponseBody = BoxBody
type ResponseBody = BoxBody
Responses body given by the service.
Source§type Error = WebTonicError
type Error = WebTonicError
Errors produced by the service.
Source§type Future = Pin<Box<dyn Future<Output = Result<Response<BoxBody>, WebTonicError>> + 'a>>
type Future = Pin<Box<dyn Future<Output = Result<Response<BoxBody>, WebTonicError>> + 'a>>
The future response value.
Auto Trait Implementations§
impl<'a> Freeze for Client<'a>
impl<'a> !RefUnwindSafe for Client<'a>
impl<'a> !Send for Client<'a>
impl<'a> !Sync for Client<'a>
impl<'a> Unpin for Client<'a>
impl<'a> !UnwindSafe for Client<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request