DemiDust
DemiDust

Reputation: 333

Grpc when should i use json encoding rather than it's usual encoding?

From what i understood, grpc has it owns encoding mechanism that compress it and makes it much more faster than json. Grpc proto 3 introduced JSON encoding in place, which i assumed will make things slower and might not differ so much from usual rest api over http/2.

Are there any cases where i might use json encoding for grpc?

Upvotes: 0

Views: 1354

Answers (1)

DazWilkin
DazWilkin

Reputation: 40061

Protobufs supports a JSON mapping to facilitate converting between JSON and Protobufs messages. See:

https://developers.google.com/protocol-buffers/docs/proto3#json

But (!) the binary, "wire format" encoding remains unchanged.

The reason for the JSON mapping is that, the popularity of JSON (in part because of it's use in REST APIs) makes it reasonably common to want to convert data between JSON and Protobuf messages. The JSON mapping can be used to automate this process; further reducing developer toil.

An example where this is useful is when building gRPC APIs which use Protobufs (by default) but wanting to provide a REST-based API as a proxy to the gRPC services for those clients not ready to make the move.

Upvotes: 1

Related Questions