2
votes

I am grpc rookie and wanted to create a REST endpoint for health check of the grpc server. For this I decided to use grpc gateway.

However, the example in docs for grpc-REST gateway for proxying grpc to json are only given for Golang. But I have a backend of python and want to use Google Cloud Endpoints to make a gRPC based api that can transcode incoming REST requests.

I did find a manual method of annotation generation in this stackoverflow answer . But I was wondering what is the best method of doing it. This is the sample .proto file I want to generate into a class.

 syntax = "proto3";
 package example;
+
+import "google/api/annotations.proto";
+
 message StringMessage {
   string value = 1;
 }

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

How can I generate .proto files and create the grpc-gateway using python backend?

2
Found a solution for generating the GoogleAPI annotation .proto files here : stackoverflow.com/questions/46131022/…Shivansh Jagga
No I have to set up the reverse proxy in PythonShivansh Jagga

2 Answers

3
votes

grpc-gateway is a project that generates a reverse proxy that translates incoming JSON requests to gRPC. To do so, it generates Go code which is then compiled into the reverse proxy binary. You then deploy the reverse proxy binary alongside your intended backend , which would be written in Python in your case. The language the reverse proxy is written in should have no bearing on the language your backend is written in.

0
votes

For proto generation, please take a look at our quick start guide for gRPC Python. grpc-gateway project also has a nice tutorial for how to setup the gateway process.