Home > Blockchain >  How can a REST endpoint call a method in gRPC server/ microservice?
How can a REST endpoint call a method in gRPC server/ microservice?

Time:03-15

I am very very new to gRPC and according to my requirement just wanted to know if this is possible, if yes then how ?

I have a rest API application with endpoints, how can this rest api call a gRPC server method or client method ?

Ideally I want to know if a rest api can communicate with a microservice (which is a api service with a list of endpoints) via gRPC and return the response to the calling rest API. Both the rest API and the microservice is written in c#, .Net core 3.0

Thanks in advance.

enter image description here

CodePudding user response:

Yes, you can use grpc-gateway to do this like:

  rpc Echo(StringMessage) returns (StringMessage) {
    option (google.api.http) = {
      post: "/v1/example/echo"
      body: "*"
    };
  }

Then you can call gRPC service Echo by HTTP with url /v1/example/echo. The grpc-gateway could be an independent application write by golang, and it will handle http request and convert as gRPC request.

  • Related