Skip to main content
Bruno lets you write JavaScript that runs at specific points in a gRPC call’s lifecycle. Use scripts to set metadata before the call starts, inspect messages as they are sent and received, and run tests against the final status and trailers.
gRPC scripting is a Beta feature. Enable it under Preferences → Beta → gRPC Scripting before the Script tab appears on gRPC requests. See Preferences.

Lifecycle hooks

Open a gRPC request and select the Script tab. The tab contains one editor per hook: For a unary call, each hook runs once. For streaming calls, the message hooks run once per message sent or received.

The bru.grpc API

gRPC scripts use the same bru object as HTTP scripts for variables, assertions, and utilities. Instead of the req and res globals, the request and response models live under bru.grpc.
Everything under bru.grpc is read-only, with one exception: bru.grpc.request.metadata accepts writes in the Before Call Start hook. Calling a write method on metadata in any other hook throws an error. bru.runRequest() is not supported in gRPC scripts.

bru.grpc.request

bru.grpc.response

Available in the After Message Receive and After Call End hooks.
In After Message Receive the call is still open, so statusCode, statusText, duration, and trailers are not yet known and read as undefined or empty. They are complete in After Call End.

Metadata methods

metadata on the request and metadata and trailers on the response share the same list API. Keys are matched case-insensitively. Write methods work only on bru.grpc.request.metadata in the Before Call Start hook.

Message methods

messages on the request and response is a read-only list. Each message is a { data, timestamp } object, where data is the decoded message payload.

Examples

Set an auth token in metadata before the call starts:
Capture a value from a received message:
Test the final call status and trailers:
Test results and script errors appear in the response pane, grouped by the hook they came from.