Deploying Your API as a gRPC Service

In certain scenarios, such as when you’re conducting service-to-service communications across your internal network, you might want to deploy your Thriftly API as a gRPC service.

As you might already know, Google developed gRPC, and protocol buffers, to allow clients running in a variety of languages to call services written in other languages. To do this, gRPC’s protocol buffers serialize a service’s structured data within proto files.

When called and formatted from within a client, these proto files allow that client to connect to a gRPC service, no matter what language the client is using or the service was originally written in.

To let you use your Thriftly APIs as gRPC services, we’ve included gRPC among the list of transports and protocols we support. After you deploy your API as a gRPC service, you can generate and access your API’s proto file, allowing you to connect with it just as you would any other gRPC service.

Note that, currently, Thriftly gRPC services include the following limitations:

  • You can not deploy Thriftly-based gRPC services using the Thriftly Gateway; you must deploy and access them from your local machine using localhost ports.

  • You can not use request headers to transform your API into a gRPC service after deployment. If you intend to use your API as a gRPC service, you must specify your API is a gRPC service as you deploy it from Thriftly.

  • Thriftly gRPC services support only the simple RPC method, not response-streaming, request-streaming, or bidirectionally-streaming RPC. (For more information on what this means, click here.)

  • Thriftly implements gRPC over HTTP2. Thriftly gRPC services are not compatible with HTTP1 implementations.

Deploying and Connecting to gRPC Services

To use your API as a gRPC service, you must:

  1. Select GRPC and PROTOBUF as your API’s transport and protocol, as described in step 4 of the Adding Endpoints section.

  2. After you finish deploying your API (as described in the Running Your Application and Viewing Your Endpoints on the Web section), access its proto file. To do so:

    1. In your web browser, access your API from its localhost location, using the port you specified as you configured your endpoint.

    2. Type ?proto at the end of the localhost address to download and open your API’s proto file.

  3. Use gRPC.io’s instructions to connect your gRPC service to a client. Largely, this requires:

    1. Using the protocol buffer compiler (protoc) to generate a language-specific data access class from your service’s proto file.

    2. Including and calling this class from within your client application, to populate, serialize, and retrieve data from your gRPC service. As you do so, you’ll have to point to the localhost port on which you are hosting your gRPC service (when you use the CreateChannel command to access your service).

If you have any questions as you get your gRPC service up and running, we encourage you to reach out to us at support@thriftly.io.