https://github.com/devashishdxt/tonic-web-wasm-client
https://github.com/devashishdxt/tonic-web-wasm-client
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/devashishdxt/tonic-web-wasm-client
- Owner: devashishdxt
- License: other
- Created: 2022-05-25T07:06:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T16:57:06.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T07:00:19.080Z (almost 2 years ago)
- Language: Rust
- Size: 87.9 KB
- Stars: 75
- Watchers: 5
- Forks: 22
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE_APACHE
Awesome Lists containing this project
README
# tonic-web-wasm-client
Rust implementation of [`grpc-web`](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md) protocol that allows
using [`tonic`](https://crates.io/crates/tonic) in browsers via webassembly.
## Usage
To use `tonic-web-wasm-client`, you need to add the following to your `Cargo.toml`:
```toml
[dependencies]
tonic-web-wasm-client = "0.8"
```
### 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:
```rust
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:
```shell
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:
```toml
[build]
target = "wasm32-unknown-unknown"
```
### Custom `Accept` header:
This library allows you to set a custom `Accept` header for the requests. This can be useful if you need to specify
a different content type for the responses. But, be aware that if you set a custom `Accept` header, the client may
not be able to handle the response correctly.
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
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.