grpcweb

package module
v0.0.0-...-640c3e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: AGPL-3.0 Imports: 2 Imported by: 0

README

xk6-grpc-web

Build Go Report Card

xk6-grpc-web is a k6 extension that supports gRPC-Web protocol.

Build

This extension is built using xk6, a tool for building custom k6 binary.

xk6 build --with github.com/shota3506/xk6-grpc-web

Example

Unary RPC
import grpcweb from "k6/x/grpc-web";
import { check } from "k6";

const GRPC_WEB_ADDR = __ENV.GRPC_WEB_ADDR;

let client = new grpcweb.Client();

client.load([], "PATH_TO_PROTO_FILE");

export default () => {
  client.connect(GRPC_WEB_ADDR);

  data = {};
  const response = client.invoke("/helloworld.Greeter/SayHello", data);

  check(response, {
    "status is OK": (r) => r && r.status === grpcweb.StatusOK,
  });

  console.log(JSON.stringify(response));

  client.close();
};
Server streaming RPC
import grpcweb from "k6/x/grpc-web";
import { sleep } from "k6";

const GRPC_WEB_ADDR = __ENV.GRPC_WEB_ADDR;

let client = new grpcweb.Client();

client.load([], "PATH_TO_PROTO_FILE");

export default () => {
  client.connect(GRPC_WEB_ADDR);

  data = {};
  const stream = client.stream("/helloworld.Greeter/SayRepeatHello", data);

  stream.on("data", (data) => {
    console.log("Data: " + JSON.stringify(data));
  });

  stream.on("error", (e) => {
    console.log("Error: " + JSON.stringify(e));
  });

  stream.on("end", () => {
    console.log("Done");
    client.close();
  });

  sleep(0.1);
};

See examples for runnable examples.

Documentation

Overview

Package grpcweb provides a k6 extension for gRPC-Web.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL