tower-rs / tower-grpc

A gRPC client & server implementation.
MIT License
562 stars 73 forks source link

gRPC-Web support #35

Open dflemstr opened 6 years ago

dflemstr commented 6 years ago

I'd like to use tower with the gRPC-Web protocol.

Some use-cases that I'm thinking about in order of priority:

I'd like to discuss how to do this in a nice way. Here's what I was (maybe naïvely) thinking:

Does this sound sane? Are there any existing components I could leverage? Is there a smarter way to do this?

carllerche commented 6 years ago

Yeah, it sounds roughly sane. I don't know that much about the grpc-web protocol. I also am not entirely sure what the fetch API is in practice.

If you want to experiment with something, maybe try a spike in an external repo and we can go from there.

dflemstr commented 6 years ago

Just to update this issue, I'm still working on this but am stuck fixing lower-level components such as the compiler support for wasm interacting with webpack. If anybody else is reading this issue, please ping me if you are interested in helping out!

ghost commented 6 years ago

+1 from me. I use the improbable one with golang and would jump onto a rust version in an instant.

ghost commented 6 years ago

Btw the scope is sane. It's exactly what I do in golang currently. Golangs wasm is still a bit rough around the edges, but the rust wasm is pretty solid, so it's definitely worthwhile pursuing this

johanbrandhorst commented 5 years ago

Just chiming in that I've thought about doing this asynchronously but that it would be cool to contribute to an existing effort. I've got a pretty good idea of how the gRPC-Web protocol works and how to use the Fetch API with it, but I'm very inexperienced with Rust. Please let me know how I can help!

johanbrandhorst commented 5 years ago

I don't think it's worthwhile implementing a wrapper around the Improbable grpc-web client, just write the whole thing in WASM, it's not really a large amount of logic and you can probably copy most of it from the open source client.

lalomartins commented 5 years ago

I'm not sure where the talk about WASM is coming from, that's IMO out of scope — we don't need a new grpc-web client-side implementation and if we did it would have little to do with tower. As I understand it the idea here is to add support for the server side grpc-web protocol to tower, so that I can write a server in Rust with tower and that server will support both regular grpc clients and grpc-web clients.

Edit: ok, the original request does talk about both. But I think if a client-side WASM implementation is wanted at all, it should probably be a separate ticket or even a separate project.

johanbrandhorst commented 5 years ago

Great, thanks for the clarification. I understand the distinction. In any case @dflemstr, please reach out (@JohanBrandhorst on twitter) because I'd love to collaborate on a client implementation. The server side, again, should be fairly trivial and translatable from the Improbable gRPC-Web proxy.

dflemstr commented 5 years ago

@johanbrandhorst I decided to spend my time on other things while waiting for the tower ecosystem to mature a bit before spending more time on this. Maybe now is a good time to continue.

What I would like to have is a detailed understanding of how to translate a gRPC-Web request to gRPC and vice versa. Right now there is only the Go reference implementation which is a bit hard to follow (it mutates request objects here and there and has an interesting way of stashing away request trailers etc).

Given that we have that, a tower wrapper should be easy to add.

I am also interested in a client implementation, that can be compiled to WASM for use client side. This enables a lot of code sharing between server and client which is quite nice.

mash-graz commented 5 years ago

a working implementation of gRPC-web in rust would be indeed very useful, but more satisfying support for twirp (= http1.1 protobuf+json fallback for simple browser access) in tower could be even more desirable.

johanbrandhorst commented 5 years ago

@mash-graz I think that could be covered under a separate issue.

mash-graz commented 5 years ago

@johanbrandhorst done! => #185

micfan commented 5 years ago

I have just tested this "unofficial" grpc-web repo, it move far than the official grpc-web. The improbable-eng/grpc-web can work with Golang gRPC server.

A WSAM Rust client runing in Browser, connecting to server via HTTP2, exposing API to JS/TS... I'm frustrated, that is a huge project

johanbrandhorst commented 4 years ago

As mentioned in https://github.com/hyperium/tonic/issues/31, I've created a sandbox repo to play around with prototyping this: https://github.com/johanbrandhorst/rust-grpc-web-wasm-test. It's currently just a Go gRPC server with the gRPC-Web proxy, the idea is that we can manually try to implement a first pass on a Rust WASM client. See the README for more information.