Need help with grpc-web?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

5.8K Stars 548 Forks Other 812 Commits 179 Opened issues


gRPC for Web Clients

Services available


Need anything else?

Contributors list

gRPC Web

A JavaScript implementation of gRPC for browser clients. For more information, including a quick start, see the gRPC-web documentation.

gRPC-web clients connect to gRPC services via a special proxy; by default, gRPC-web uses Envoy.

In the future, we expect gRPC-web to be supported in language-specific web frameworks for languages such as Python, Java, and Node. For details, see the roadmap.

Java gRPC-web in-process proxy implementation is in beta stage. For details, see details.

Quick Start

Eager to get started? Try the Hello World example. From this example, you'll learn how to do the following:

  • Define your service using protocol buffers
  • Implement a simple gRPC Service using NodeJS
  • Configure the Envoy proxy
  • Generate protobuf message classes and client service stub for the client
  • Compile all the JS dependencies into a static library that can be consumed by the browser easily

Advanced Demo: Browser Echo App

You can also try to run a more advanced Echo app from the browser with a streaming example.

From the repo root directory:

$ docker-compose pull node-server envoy commonjs-client
$ docker-compose up node-server envoy commonjs-client

Open a browser tab, and visit http://localhost:8081/echotest.html.

To shutdown:

docker-compose down

Runtime Library

The gRPC-web runtime library is available at

$ npm i grpc-web

Code Generator Plugin

You can download the

protoc plugin from our release page:

If you don't already have

installed, you will have to download it first from here.

Make sure they are both executable and are discoverable from your PATH.

For example, in MacOS, you can do:

$ sudo mv ~/Downloads/protoc-gen-grpc-web-1.2.1-darwin-x86_64 \
$ chmod +x /usr/local/bin/protoc-gen-grpc-web

Client Configuration Options

Typically, you will run the following command to generate the proto messages and the service client stub from your

$ protoc -I=$DIR echo.proto \
    --js_out=import_style=commonjs:$OUT_DIR \

You can then use Browserify, Webpack, Closure Compiler, etc. to resolve imports at compile time.

Import Style

: The default generated code has Closure
import style.

: The CommonJS style
is also supported.

: (Experimental) In addition to above, a
typings file will also be generated for the protobuf messages and service stub.

: (Experimental) The service stub will be generated in TypeScript. See TypeScript Support below for information on how to generate TypeScript files.

Note: The

styles are only supported by
, not by

Wire Format Mode

For more information about the gRPC-web wire format, see the specification.

: The default generated code sends the payload in the
  • Content-type: application/grpc-web-text
  • Payload are base64-encoded.
  • Both unary and server streaming calls are supported.

: A binary protobuf format is also supported.
  • Content-type: application/grpc-web+proto
  • Payload are in the binary protobuf format.
  • Only unary calls are supported for now.

How It Works

Let's take a look at how gRPC-web works with a simple example. You can find out how to build, run and explore the example yourself in Build and Run the Echo Example.

1. Define your service

The first step when creating any gRPC service is to define it. Like all gRPC services, gRPC-web uses protocol buffers to define its RPC service methods and their message request and response types.

message EchoRequest {
  string message = 1;


service EchoService { rpc Echo(EchoRequest) returns (EchoResponse);

rpc ServerStreamingEcho(ServerStreamingEchoRequest) returns (stream ServerStreamingEchoResponse); }

2. Run the server and proxy

Next you need to have a gRPC server that implements the service interface and a gateway proxy that allows the client to connect to the server. Our example builds a simple Node gRPC backend server and the Envoy proxy.

For the Echo service: see the service implementations.

For the Envoy proxy: see the config yaml file.

3. Write your JS client

Once the server and gateway are up and running, you can start making gRPC calls from the browser!

Create your client:

var echoService = new proto.mypackage.EchoServiceClient(

Make a unary RPC call:

var request = new proto.mypackage.EchoRequest();
var metadata = {'custom-header-1': 'value1'};
echoService.echo(request, metadata, function(err, response) {
  if (err) {
  } else {

Server-side streaming is supported!

var stream = echoService.serverStreamingEcho(streamRequest, metadata);
stream.on('data', function(response) {
stream.on('status', function(status) {
stream.on('end', function(end) {
  // stream end signal

For an in-depth tutorial, see this page.

Setting Deadline

You can set a deadline for your RPC by setting a

header. The value should be a Unix timestamp, in milliseconds.
var deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 1);

client.sayHelloAfterDelay(request, {deadline: deadline.getTime()}, (err, response) => { // err will be populated if the RPC exceeds the deadline ... });

TypeScript Support


module can now be imported as a TypeScript module. This is currently an experimental feature. Any feedback welcome!

When using the

protoc plugin, mentioned above, pass in either:
  • import_style=commonjs+dts
    : existing CommonJS style stub +
  • import_style=typescript
    : full TypeScript output

Do not use

, it will silently be ignored. Instead you should use
, or
if you are using
. The
plugin will generate JavaScript code (
), and the
plugin will generate a TypeScript definition file for it (
). This is a temporary hack until the
supports TypeScript itself.

For example, this is the command you should use to generate TypeScript code using the binary wire format

$ protoc -I=$DIR echo.proto \
  --js_out=import_style=commonjs,binary:$OUT_DIR \

It will generate the following files:

  • echo_grpc_web_pb.ts
    - Generated by
    , contains the TypeScript gRPC-web code.
  • echo_pb.js
    - Generated by
    , contains the JavaScript Protobuf code.
  • echo_pb.d.ts
    - Generated by
    , contains TypeScript definitions for
import * as grpcWeb from 'grpc-web';
import {EchoServiceClient} from './echo_grpc_web_pb';
import {EchoRequest, EchoResponse} from './echo_pb';

const echoService = new EchoServiceClient('http://localhost:8080', null, null);

const request = new EchoRequest(); request.setMessage('Hello World!');

const call = echoService.echo(request, {'custom-header-1': 'value1'}, (err: grpcWeb.Error, response: EchoResponse) => { console.log(response.getMessage()); }); call.on('status', (status: grpcWeb.Status) => { // ... });

For the full TypeScript example, see ts-example/client.ts.

Proxy Interoperability

Multiple proxies support the gRPC-web protocol. The current default proxy is Envoy, which supports gRPC-web out of the box.

$ docker-compose up -d node-server envoy commonjs-client

You can also try the gRPC-web Go proxy.

$ docker-compose up -d node-server grpcwebproxy binary-client

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.