Crates.io | tonic-web-wasm-client |
lib.rs | tonic-web-wasm-client |
version | 0.6.0 |
source | src |
created_at | 2022-05-25 14:10:47.399298 |
updated_at | 2024-07-28 20:06:48.546141 |
description | grpc-web implementation for use by tonic clients in browsers via webassembly |
homepage | https://github.com/devashishdxt/tonic-web-wasm-client |
repository | https://github.com/devashishdxt/tonic-web-wasm-client |
max_upload_size | |
id | 593547 |
size | 55,975 |
Rust implementation of grpc-web
protocol that allows
using tonic
in browsers via webassembly.
To use tonic-web-wasm-client
, you need to add the following to your Cargo.toml
:
[dependencies]
tonic-web-wasm-client = "0.6"
To use tonic
gRPC clients in browser, compile your code with tonic's transport
feature disabled (this will disable
the default transport layer of tonic). Then initialize the query client as follows:
use tonic_web_wasm_client::Client;
let base_url = "http://localhost:9001"; // URL of the gRPC-web server
let query_client = QueryClient::new(Client::new(base_url)); // `QueryClient` is the client generated by tonic
let response = query_client.status().await; // Execute your queries the same way as you do with defaule transport layer
Since tonic-web-wasm-client
is primarily intended for use in browsers, a crate that uses tonic-web-wasm-client
can only be built for wasm32
target architectures:
cargo build --target wasm32-unknown-unknown
Other option is to create a .cargo/config.toml
in your crate repository and add a build target there:
[build]
target = "wasm32-unknown-unknown"
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.