#grpc #tonic #grpc-client #wasm-client #transport-layer

tonic-web-wasm-client

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

14 releases

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

#152 in WebAssembly

Download history 600/week @ 2023-12-23 1122/week @ 2023-12-30 2252/week @ 2024-01-06 1574/week @ 2024-01-13 1389/week @ 2024-01-20 1464/week @ 2024-01-27 1426/week @ 2024-02-03 1560/week @ 2024-02-10 1527/week @ 2024-02-17 1539/week @ 2024-02-24 1371/week @ 2024-03-02 1540/week @ 2024-03-09 1625/week @ 2024-03-16 2049/week @ 2024-03-23 1938/week @ 2024-03-30 2009/week @ 2024-04-06

7,911 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

41KB
761 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.5"

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

~11–15MB
~272K SLoC