#grpc #grpc-client #tonic #wasm-client #web-client

tonic-web-wasm-client

grpc-web implementation for use by tonic clients in browsers via webassembly

15 releases

0.6.0 Jul 28, 2024
0.5.1 Feb 11, 2024
0.5.0 Sep 28, 2023
0.4.0 May 4, 2023
0.2.1 Jul 30, 2022

#32 in WebAssembly

Download history 3940/week @ 2024-08-17 2719/week @ 2024-08-24 3095/week @ 2024-08-31 3243/week @ 2024-09-07 3512/week @ 2024-09-14 2475/week @ 2024-09-21 2078/week @ 2024-09-28 2870/week @ 2024-10-05 2661/week @ 2024-10-12 2223/week @ 2024-10-19 2660/week @ 2024-10-26 5119/week @ 2024-11-02 4408/week @ 2024-11-09 3936/week @ 2024-11-16 5027/week @ 2024-11-23 4786/week @ 2024-11-30

18,909 downloads per month
Used in 17 crates (8 directly)

MIT/Apache

42KB
762 lines

tonic-web-wasm-client

Rust implementation of grpc-web protocol that allows using tonic in browsers via webassembly.

Usage

To use tonic-web-wasm-client, you need to add the following to your Cargo.toml:

[dependencies]
tonic-web-wasm-client = "0.6"

Example

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

Building

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"

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~17–23MB
~332K SLoC