Is it possible to simultaneous accept JSON and protobuf payload?

68 views
Skip to first unread message

Glen Huang

unread,
Feb 11, 2019, 7:07:51 AM2/11/19
to grpc.io
I have a grpc server, and I'm wondering if it's possible to make it accept JSON and protobuf payload simultaneously? I want to use the server for both backend and frontend communications.

By that I mean, if I have a proto definition like this:

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

and set up a grpc server to listen at port 1234 for example. Obviously I can use grpc client to talk to it via port 1234. But Is it possible that I can send an http request with a particular JSON payload and path to the same port, that can call the SayHello on the server?

I heard it's pretty expansive to encode and decode protobuf with javascript, so I hope I could keep using JSON and make grpc accept it automatically.

Is that something already feasible?

I use Golang btw.

Thanks in advance.

Danesh Kuruppu

unread,
Feb 11, 2019, 11:37:40 PM2/11/19
to grpc.io
Hi Glen,

This is not exactly what you need, but this generates reverse proxy server which translates JSON to protobuf payload. So it serves in different port but using same backend gRPC service.

Thanks
Danesh

Doug Fawley

unread,
Feb 13, 2019, 6:43:58 PM2/13/19
to grpc.io
Similarly, you may also want to look at grpc-web: https://github.com/grpc/grpc-web.

Thanks,
Doug

Glen Huang

unread,
Feb 14, 2019, 6:00:45 AM2/14/19
to grpc.io
 Looks like a proxy is inevitable. Thanks guys. I'll check them out.
Reply all
Reply to author
Forward
0 new messages