tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Support gRPC-gateway annotations

Open jgall opened this issue 5 years ago • 7 comments
trafficstars

Feature Request

Motivation

A frequent use-case on top of gRPC is to expose a REST API built to mirror the RPC defined in your proto file. The grpc-gateway plugin for protoc does just that, automatically. I think it would be great if we could optionally support these same annotations (perhaps behind a feature flag or in a different crate?).

Proposal

Functional drawbacks:

  • Might be considered feature-creep/bloat since it's not a part of the official proto spec.
  • This is potentially a lot of work. (Almost DEFINITELY a lot of work)

Alternatives

One could conceivably write an entirely different crate that wraps Tonic and pre-processes the grpc-gateway annotations to create a REST API and some stubs that the user could hook in to their Tonic trait impls.

jgall avatar Apr 20 '20 17:04 jgall

Two main things that are somewhat blockers for this:

  • Getting support for this within prost and exposed generically within tonic.
  • Finding a way to get this support for flatbuffers as well.

I think trying to get the prost support would be a good first step!

LucioFranco avatar Apr 27 '20 15:04 LucioFranco

I suggest that google grpc http transcoding annotations be used here to maintain a standard between frameworks and tools https://cloud.google.com/endpoints/docs/grpc/transcoding

sleipnir avatar Apr 30 '20 05:04 sleipnir

Is there any update on this? It would be a fantastic feature to add.

I've been trying to figure out how to do this (as a consumer of tonic, not by cracking it open), and have come across a few articles that make it seem like it should work, but I haven't had much luck. I've been able to compile it with annotations, but issuing HTTP requests to the alleged REST endpoints oddly returns status 200 OK, but with no content, and the GRPC endpoint handler isn't being called.

Links:

  • https://cloud.google.com/endpoints/docs/grpc/transcoding (formal spec; sleipnir linked this in the previous post)
  • https://github.com/DazWilkin/rust-googleapis
  • https://grpc.io/blog/coreos/ (talks about the transcoding abstractly but nothing concrete)
  • https://earvinkayonga.com/posts/grpc-annotations-and-rust/ (this one is only about generating Swagger APIs from annotations, but I figured I'd include it as peripherally related).

vdods avatar Jul 22 '21 23:07 vdods

I believe the first step is to add support for this in prost. I want to say https://github.com/tokio-rs/prost/issues/301 this is the closet issue to what you may want.

LucioFranco avatar Jul 27 '21 15:07 LucioFranco

I assume that no more progress has been made on this, correct?

Cliftonz avatar Sep 27 '22 03:09 Cliftonz

Correct, we have not made much progress on the prost side of things.

LucioFranco avatar Sep 27 '22 14:09 LucioFranco