How to test gRPC services with an API client
gRPC is great for services talking to services: typed contracts, small binary messages, streaming. It's less great for humans. You can't paste a gRPC call into a browser, and grpcurl commands get long fast. An API client that speaks gRPC lets you call a method by picking it from a list and typing the message as JSON.
Create a gRPC request
Create a request and set its type to gRPC. Its tabs:
| Tab | What goes there |
|---|---|
| Message | The request message as JSON |
| Metadata | gRPC metadata, the equivalent of HTTP headers |
| Authorization | Auth translated into metadata, inherited from the collection like any other request |
| Service definition | Server reflection, or a proto definition, plus the service and method |
| Scripts | Before invoke, On message and After response |
| Settings | TLS or plaintext, TLS server name, reflection timeout, maximum response size, default value emission and call timeout |
Reflection or proto
There are two ways for the client to know a service's methods and message types:
- Server reflection. If the server has the reflection service enabled (common in development and staging), point the request at the server and pick the service and method from what it reports. Nothing to keep in sync.
- A proto definition. If reflection is off, as it often is in production, provide the service definition yourself.
The message is JSON
You write the request message as JSON, using the proto's field names:
{
"order_id": "{{orderId}}",
"include_items": true
}{{variables}} work inside the message and in metadata, so the same request runs against every environment. Turn on default value emission in Settings if you want fields with default values (0, "", false) to show up in the response instead of being omitted, which is how proto3 encodes them.
Metadata and auth
Authentication in gRPC is metadata, usually authorization: Bearer …. Set auth on the collection as for HTTP requests and gRPC requests inherit it. For anything custom, add rows in Metadata:
x-tenant-id: {{tenantId}}
x-request-id: {{$guid}}TLS, plaintext and deadlines
Local services often run in plaintext; staging and production use TLS. Settings lets you choose per request, set the TLS server name when you connect through an IP or a tunnel, and set a call timeout. A deadline that's too short is one of the most common causes of DEADLINE_EXCEEDED errors in testing.
Status codes are different
gRPC has its own status codes, separate from HTTP: OK, INVALID_ARGUMENT, NOT_FOUND, PERMISSION_DENIED, UNAUTHENTICATED, DEADLINE_EXCEEDED, UNAVAILABLE and others. When a call fails, look at the gRPC status and its message, not an HTTP code.
Scripts
Scripts work for gRPC as for HTTP: prepare metadata or the message in Before invoke, inspect streamed messages in On message, and check and store results in After response. Collection and folder scripts for the same phase run first.
Where gRPC runs
Keeping gRPC, REST and GraphQL requests for the same system in one collection, with shared auth and environments, is still the main win: one place to look when something breaks between services.