tokio-rs / axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper
18.5k stars 1.04k forks source link

Support for gRPC (Tonic) #1052

Closed rohitjoshi closed 2 years ago

rohitjoshi commented 2 years ago

Feature Request

Supporting gRPC (tonic) based on the content-type header. I came across "Combining Axum, Hyper, Tonic, and Tower for hybrid web/gRPC apps" which shows the gRPC with Axum but seems cumbersome.

Motivation

This will enable browser support and code reuse across both HTTP1/1 and gRPC clients.

Proposal

It would be good to provide native support with maybe a separate crate e.g. axum-grpc.

Alternatives

davidpdrsn commented 2 years ago

Sounds like you're asking for this example https://github.com/tokio-rs/axum/blob/main/examples/rest-grpc-multiplex/src/main.rs. That combines a REST and gRPC service into one and dispatches based on the content-type. All possible thanks to tower::Service.

Actually tonic already uses axum internally for routing. See https://github.com/hyperium/tonic/blob/master/tonic/src/transport/service/router.rs

rohitjoshi commented 2 years ago

Thanks. Closing..