How To Use Postman To Make GRPC Requests

How To Use Postman To Make GRPC Requests

August 2, 2022

gRPC is an open source remote procedure call (RPC) framework developers use to build APIs. It operates over HTTP/2 and is frequently used in the context of microservices. The gRPC protocol is often paired with Protocol Buffers (a.k.a. protobuf), a binary message format.

This site is a great source for people completely new to gRPC.

Your common debugging workflow changes when you move from JSON-based REST APIs over HTTP to inspecting binary messages over gRPC and HTTP/2. This tutorial shows you how to use Postman – a common developer tool for testing APIs – with gRPC microservices that have .proto schemas.

Configuring Postman with a .proto file

We will be using gRPC requests with Wasmflow hosts in these examples.

First, ensure you have the latest Postman installed. GRPC support is new and older versions won’t have these menus.

Protocol buffers require a schema, unlike JSON or YAML. That makes the messages smaller than the alternatives but it requires every client and server to know the schema beforehand. That’s where .proto files come in. A .proto file is a language-agnostic description of the services and schemas in your API. Code generators use .proto files to automatically create code the code for your API. You’ll need your .proto file to set Postman up to communicate with your service.

We’re using the “wasmflow.proto” definition found here.

When you have your .proto file, open Postman, hit New and then gRPC Request.

Then click into the field with the text Select a method and choose Import a .proto file.

Select your .proto file or the tutorial’s wasmflow.proto. Hit next and enter a name + version.

Congrats! You should now be able to make API calls.

How to make gRPC Requests in Postman

All wasmflow hosts can be configured to expose a gRPC service to invoke components, query statistics, or get the list of running components. We will invoke the list component on a local wasmflow host. Our sample list component takes no input and returns a list of simple objects.

Fill out the server URL and select a method. Your URL should include the port your application is running on and the method in the drop-down menu should be invoke for our Wasmflow host.

Enter the following JSON in the message field. This message format is Wasmflow specific so remember to modify it if you are using your own service. If you are testing your own Wasmflow components, remember to change the target of your message to refer to your component and add a payload field if your component accepts inputs.

  "origin": "wafl://test.client/",
  "id": "6530adb5-aa1e-4694-879c-b8dc6dd2e58c",
  "target": "wafl://__local__.coll/list",
  "tx_id": "6530adb5-aa1e-4694-879c-b8dc6dd2e58f"

Hit invoke and you should see request and response output in the Postman console.

Written By
Shazaib Nasrullah
Shazaib Nasrullah