hyperium / tonic

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

[user guide] How can I write a plain HTTP route with this? #1287

Closed rollo-b2c2 closed 1 year ago

rollo-b2c2 commented 1 year ago

Forgive the basic question, but what's a sensible way of adding a plain HTTP route to the Server.

I'd like to have some plain HTTP routes on some non GRPC paths. Is this possible?

w41ter commented 1 year ago

Forgive the basic question, but what's a sensible way of adding a plain HTTP route to the Server.

I'd like to have some plain HTTP routes on some non GRPC paths. Is this possible?

We have implemented this before, here is an example:

Implement an HTTP handle

https://github.com/engula/engula/blob/9901b7cd7c8460bd37f55389617de27f37dbb778/src/server/src/service/admin/service.rs#L55-L81

Then add the service to the tonic server.

https://github.com/engula/engula/blob/9901b7cd7c8460bd37f55389617de27f37dbb778/src/server/src/bootstrap.rs#L92

LucioFranco commented 1 year ago

This uses warp but you can apply the same to axum. https://github.com/hyperium/tonic/blob/master/examples/src/hyper_warp_multiplex/server.rs