hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.77k stars 997 forks source link

web-grpc client (non-WASM) from Rust. #829

Closed ereOn closed 1 year ago

ereOn commented 2 years ago

Feature Request

Crates

tonic-web

Motivation

We recently managed to make AWS Lambda gRPC compatible thanks to tonic and tonic-web.

There is however currently no way to call those from pure Rust clients, as they require HTTP2 and the whole thing we did expects gRPC web.

Proposal

Not sure exactly. I'd like to implement that, but I'd really appreciate some guidance as to what is the best way to proceed.

If you agree such a feature is indeed desirable, could you give me a hint on how to implement it?

Thanks!

Alternatives

Not really. Perhaps I missed something.

ereOn commented 2 years ago

Well, I finally managed to implement something that works well.

But, as I suspect - given the lack of reaction until now - there is no real interest in supporting that in tonic-web, I won't bother trying to make it match the current library standards.

Let me know if that ever changes.

john-h-k commented 1 year ago

Any information about how you did this?

ereOn commented 1 year ago

@john-h-k Our startup was eventually closed but all our code was open-source.

I think you'll find what you are looking for here: https://github.com/legion-labs/legion/blob/main/crates/lgn-online/src/grpc/web/client.rs

Disclaimer: it is probably not the best Rust code around: we had just started learning Rust. Still, it did work. I had to read on a whole of cryptic gRPC documentation.

Our resulting code would wrap a regular HTTP 1.1 endpoint and fake an HTTP2 content (on both the way in and the way out) as to satisfy tonic's requirements.

The main limitation, from what I recall, is that since gRPC/web can't benefit from server pipelining, you can't support streaming requests.

It's been a while since I wrote this so sorry if I can't give out more detailed information. Hopefully that still helps.

LucioFranco commented 1 year ago

This now exists via https://github.com/hyperium/tonic/pull/1472