gRPC JSON transcoding

Introduction

Our gRPC mock servers support protocol transcoding so that you can access your gRPC mock API by using REST+JSON. gRPC/gRPC-web protocols can still be used to call your services.

How it works

Every gRPC mock method has corresponding REST method which is constructed using the template below:

HTTP Method and Url

POST https://<host>/<package>.<service>/<method>

where package, service and method are taken from your .proto file

For example

POST https://Greeter→demo→mockqa.grpc.qa/demo.Greeter/SayHello

Please find the Endpoint URL builder on your mock.qa dashboard which helps you to build a correct URL for your mock

HTTP Body

Mapping from gRPC request/response to REST JSON request/response and vice-versa provided by protobuf canonical encoding in JSON implemented by Google Protocol Buffers library.

HTTP Request status

gRPC status and status message fields are included to response as HTTP headers:

  • grpc-status
  • grpc-message

How to send REST request to gRPC mock server

Here is the checklist to make a REST+JSON request to gRPC mock

  • HTTP method is POST
  • URL matches the URL template above
  • Content-Type header is set to application/json
  • Request body is a valid JSON (or empty)

Limitations

Streaming

Client streaming and duplex streaming are not supported with REST+JSON transcoding. An attempt to make a REST request to such methods will lead to HTTP 408-RequestTimeout error (gRPC status 1-Cancelled).

google.api transcoding

google.api annotations are not supported yet. Planned for future releases.

Demo

To see transcoding in action, try mock.qa gRPC playground, which is built on transcoding feature.