Skip to content

Mocking a gRPC service

Right-click a folder ▸ Add ▸ gRPC server.

Each mocked method is a list entry:

FieldRole
Service / MethodWhat is served
Call typeunary, server-stream, client-stream, bidirectional-stream
Response messageThe message returned, in JSON — a JSON array for a stream, each element being one frame
Status code0 for OK, or any other gRPC code
Status messageThe message that goes with it
Trailing metadataThe trailers
ScriptJavaScript, which wins over the response message

A gRPC server item: the listening port, reflection enabled, the embedded proto descriptor, and the list of mock methods with their service, call type, status code and response message

This is the most rewarding use: reproducing the status codes your client has to know how to handle.

CodeUseful for testing
4 DEADLINE_EXCEEDEDBehaviour when a deadline is exceeded
8 RESOURCE_EXHAUSTEDRate limiting
14 UNAVAILABLEFallback and retry
16 UNAUTHENTICATEDToken renewal

Fill in the code, the message and the trailing metadata, then check your client reacts correctly.

For a streaming mode, the response message is a JSON array: each element is sent as its own frame.

The server exposes the gRPC reflection service by default. Your clients — including grpcurl and Restorm’s own reflection import — can therefore discover the service without a .proto.

Two fields, tlsCertPem and tlsKeyPem, accept a certificate and a key in PEM form, for serving over TLS.

The gRPC server and gRPC server close actions. See Hosted servers.