tonic
tonic copied to clipboard
Support gRPC-gateway annotations
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.
Two main things that are somewhat blockers for this:
- Getting support for this within
prostand 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!
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
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).
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.
I assume that no more progress has been made on this, correct?
Correct, we have not made much progress on the prost side of things.