From 4e0d2fc598723ae57502a6468e697b89aa936ef1 Mon Sep 17 00:00:00 2001 From: Juan Alvarez Date: Fri, 4 Jun 2021 16:26:15 -0500 Subject: [PATCH] chore(tonic-web): add crate metadata and README (#675) --- tonic-web/Cargo.toml | 12 +++++++++++- tonic-web/README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tonic-web/README.md diff --git a/tonic-web/Cargo.toml b/tonic-web/Cargo.toml index e912c97..bc6b722 100644 --- a/tonic-web/Cargo.toml +++ b/tonic-web/Cargo.toml @@ -1,8 +1,18 @@ [package] name = "tonic-web" version = "0.1.0" -authors = ["Juan Alvarez "] +authors = ["Juan Alvarez "] edition = "2018" +license = "MIT" +documentation = "https://docs.rs/tonic-web/0.1.0/tonic-web/" +repository = "https://github.com/hyperium/tonic" +homepage = "https://github.com/hyperium/tonic" +description = """ +grpc-web protocol translation for tonic services. +""" +readme = "README.md" +categories = ["network-programming", "asynchronous"] +keywords = ["rpc", "grpc", "grpc-web"] [dependencies] tonic = { path = "../tonic", default-features = false, features = ["transport"] } diff --git a/tonic-web/README.md b/tonic-web/README.md new file mode 100644 index 0000000..71e459c --- /dev/null +++ b/tonic-web/README.md @@ -0,0 +1,46 @@ +# 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 = "0.1" + ``` + + ## 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> { + let addr = "[::1]:50051".parse().unwrap(); + let greeter = GreeterServer::new(MyGreeter::default()); + + Server::builder() + .accept_http1(true) + .add_service(tonic_web::enable(greeter)) + .serve(addr) + .await?; + + Ok(()) + } + ``` + +## Examples + +[tonic-web-demo][1]: React+Typescript app that talking to a tonic-web enabled service using HTTP/1 or TLS. + +[conduit][2]: An (in progress) implementation of the [realworld][3] demo in Tonic+Dart+Flutter. This app shows how +the same client implementation can talk to the same tonic-web enabled server using both `grpc` and `grpc-web` protocols +just by swapping the channel implementation. + +When the client is compiled for desktop, ios or android, a grpc `ClientChannel` implementation is used. +When compiled for the web, a `GrpcWebClientChannel.xhr` implementation is used instead.`` +[1]: https://github.com/alce/tonic-web-demo +[2]: https://github.com/alce/conduit +[3]: https://github.com/gothinkster/realworld