Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Client.invoke(url, request [,params])
Caution
Starting on k6
v0.49, the experimental modulek6/experimental/grpchas been graduated, and its functionality is now available in thek6/net/grpcmodule. Thek6/experimental/grpcis deprecated and will be removed inv0.51.0.To migrate your scripts, replace all
k6/experimental/grpcimports withk6/net/grpc.
Invokes an unary RPC request to the given method.
The given method to invoke must have its RPC schema previously loaded via the Client.load() function, otherwise an error will be thrown.
Client.connect() must be called first before invoking a request, otherwise an error will be thrown.
Returns
Examples
import grpc from 'k6/experimental/grpc';
import { check } from 'k6';
const client = new grpc.Client();
client.load([], 'routeguide.proto');
export default () => {
client.connect('localhost:10000', { plaintext: true });
const response = client.invoke('main.RouteGuide/GetFeature', {
latitude: 410248224,
longitude: -747127767,
});
check(response, { 'status is OK': (r) => r && r.status === grpc.StatusOK });
console.log(response.message.name);
// output: 3 Hasta Way, Newton, NJ 07860, USA
client.close();
};

