File: README.md

package info (click to toggle)
rust-tonic 0.12.3%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,300 kB
  • sloc: sh: 122; makefile: 31
file content (39 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# tonic-web

Enables tonic servers to handle requests from `grpc-web` clients directly,
without the need of an external proxy.

## Getting Started

```toml
[dependencies]
tonic-web = "<tonic-web-version>"
```

## Enabling tonic services

The easiest way to get started, is to call the function with your tonic service
and allow the tonic server to accept HTTP/1.1 requests:

```rust
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = "[::1]:50051".parse().unwrap();
    let greeter = GreeterServer::new(MyGreeter::default());

   Server::builder()
       .accept_http1(true)
       .layer(GrpcWebLayer::new())
       .add_service(greeter)
       .serve(addr)
       .await?;

   Ok(())
}
```

## Examples

See [the examples folder][example] for a server and client example.

[example]: https://github.com/hyperium/tonic/tree/master/examples/src/grpc-web