2

I use grpc-gateway to host REST api for my grpc service.

I'm have 2 api:

API A

 option (google.api.http) = {
      post: "/v1/product/{id}"
      body: "*"
    };

API B

 option (google.api.http) = {
      post: "/v1/product/unit"
      body: "*"
    };

but when i call POST v1/product/unit grpc-gateway redirect to the method with the API A. Do i miss something?

Dang.Nguyen
  • 83
  • 1
  • 7

1 Answers1

0

It depends on order in which you register your gRPC servers in gateway mux. It's not obvious but you should register more general path (/v1/product/{id}) before more exact path (/v1/product/uni). Then you should change order of registration of your gRPC servers in grpc-gatewar ServeMux

cooleck
  • 343
  • 1
  • 5
  • 14
  • thank you for the answer. These are in the same service, so i change the order on rpc function as you mention and it works. But i think it's not good to handle it like this, do we have any other way to achieve that – Dang.Nguyen Nov 05 '22 at 05:26
  • I don't think that there is any other way to solve it. This issue is usual for httprouters. Usually you should register your handlers in order from specific to general. So the exact route should be registered before the param route. – cooleck Nov 05 '22 at 18:01