2

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

Annas
  • 161
  • 1
  • 7
  • please clarify your desired call flow, i.e. what is the client, what is the server, and what protocal you want to use? – Lei Yang Mar 14 '22 at 08:56
  • I have a rest api application, which wants to communicate with the microservice - which is in turn a c# application. I want to know if the rest API can talk to the microservice via gRPC call/ communication method. If yes, then how ? I have also updated the question. – Annas Mar 14 '22 at 09:39
  • the question is still unclear. a rest api is a server concept, but in your question you seem to have a 'rest api' as client. and microservice is an archetectural and deploying concept, a microservice can be a rest api or a grpc service, or others. don't mix the concepts and confuse the readers. – Lei Yang Mar 14 '22 at 10:16
  • As seen in the diagram I am using rest api as a facade / gateway service, according to my project architecture. And the question I am trying to ask is, can a rest service communicate to a grpc service , is yes then how. The reason is we want the services to communicate with each other using grpc way of communication, for faster performance. Hope my question is clear now. – Annas Mar 14 '22 at 10:59
  • *can a rest service communicate to a grpc service* this is what i say confusing question. rest service is a service. it is not client concept. it is the **client** that communicates to a grpc service. – Lei Yang Mar 14 '22 at 11:04
  • My apologies if my question is not clear, since I am new to the concept. Thank u for the clarification.As of now I have 2 microservice - product ,cart. They are basically .Net core web API applications and talk to each other via rest calls, http get/ post/put. Now in this architecture I have to implement gRPC communication in between them, How do I do that, is my question. As you said "client that communicates to a grpc service.", should I create a gRPC client inbetween them ? This is for an ecommerce app, Product/ cart are the two microservices. Product talks to cart by http get cart/id – Annas Mar 14 '22 at 11:34
  • 1
    you just have each other implement both grpc client and server, and talk to each other. and keep rest api as server to public. – Lei Yang Mar 14 '22 at 11:39
  • Sorry for another question - so can a microservice communicate by both ways - rest api to public and gRPC client/server, to communicate to the internal services – Annas Mar 14 '22 at 11:42
  • 1
    sure. you can even have both (one or more)grpc and rest api on same server(port). – Lei Yang Mar 14 '22 at 12:19

1 Answers1

3

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.

HelloWood
  • 727
  • 4
  • 13