k6/net/grpc module provides a gRPC client for making Remote Procedure Calls (RPC) over HTTP/2.
Overview
Use this module to test gRPC services by making unary and streaming RPC calls. The module supports loading protocol buffer definitions, establishing connections, and invoking RPC methods with full support for metadata and parameters.Importing the Module
API Reference
Client Class
constructor
Creates a new gRPC client for making RPC calls to a gRPC server.
Client Methods
function
function
function
function
Asynchronously makes a unary RPC call for the given service/method.Parameters:Returns:
string
required
RPC method in format
package.Service/Methodobject
required
Request message object matching the proto definition
Params
Request-specific parameters
Promise<Response>
Promise that resolves to a gRPC Response
function
Closes the connection to the gRPC service.
Response Object
number
gRPC status code (see Constants below)
object
Response message from the server
object
Response headers/metadata
object
Response trailers/metadata
object
Error information if the call failed
Params Object
object
Custom metadata to send with the request as key-value pairs.
object
Custom metric tags for filtering results and setting thresholds.
string
Request timeout (e.g.,
"10s", "500ms")boolean
Use plaintext connection (no TLS). Default:
falseStatus Constants
The module provides constants to distinguish between gRPC response statuses:Stream Support
For bidirectional and streaming RPCs:constructor
Creates a new gRPC stream for bidirectional or streaming calls.
function
Adds an event listener for stream events:
data, error, endfunction
Writes a message to the stream.
function
Signals to the server that the client has finished sending.
gRPC Metrics
k6 automatically collects gRPC-specific metrics:Examples
Basic Unary RPC
Async Invocation
Streaming RPC
Status Code Checking
Related Resources
Response Object
gRPC response structure
Stream
Streaming RPC support
gRPC Testing Guide
Learn gRPC testing patterns
Protocol Buffers
Protocol buffer documentation