0.15.0 • Published 2 years ago

@improbable-eng/grpc-web v0.15.0

Weekly downloads
37,597
License
Apache-2.0
Repository
-
Last release
2 years ago

@improbable-eng/grpc-web

Library for making gRPC-Web requests from a browser

This library is intended for both JavaScript and TypeScript usage from a web browser or NodeJS (see Usage with NodeJS).

Note: This only works if the server supports gRPC-Web

A Golang gRPC-Web middleware and a Golang-based gRPC-Web proxy are available here.

Please see the full gRPC-Web README for known limitations.

Installation

@improbable-eng/grpc-web has peer dependencies of google-protobuf and @types/google-protobuf.

npm install google-protobuf @types/google-protobuf @improbable-eng/grpc-web --save

Example Project

There is an example project available here

Usage Overview

import {grpc} from "@improbable-eng/grpc-web";

// Import code-generated data structures.
import {BookService} from "./generated/proto/examplecom/library/book_service_pb_service";
import {GetBookRequest} from "./generated/proto/examplecom/library/book_service_pb";

const getBookRequest = new GetBookRequest();
getBookRequest.setIsbn(60929871);
grpc.unary(BookService.GetBook, {
  request: getBookRequest,
  host: host,
  onEnd: res => {
    const { status, statusMessage, headers, message, trailers } = res;
    if (status === grpc.Code.OK && message) {
      console.log("all ok. got book: ", message.toObject());
    }
  }
});
  • Requests can be aborted/cancelled before they complete:
const request = grpc.unary(BookService.GetBook, { ... });
request.cancel();

Available Request Functions

There are three functions for making gRPC requests:

grpc.unary

This is a convenience function for making requests that consist of a single request message and single response message. It can only be used with unary methods.

rpc GetBook(GetBookRequest) returns (Book) {}

grpc.invoke

This is a convenience function for making requests that consist of a single request message and a stream of response messages (server-streaming). It can also be used with unary methods.

rpc GetBook(GetBookRequest) returns (Book) {}
rpc QueryBooks(QueryBooksRequest) returns (stream Book) {}

grpc.client

grpc.client returns a client. Dependant upon transport compatibility this client is capable of sending multiple request messages (client-streaming) and receiving multiple response messages (server-streaming). It can be used with any type of method, but will enforce limiting the sending of messages for unary methods.

rpc GetBook(GetBookRequest) returns (Book) {}
rpc QueryBooks(QueryBooksRequest) returns (stream Book) {}
rpc LogReadPages(stream PageRead) returns (google.protobuf.Empty) {}
rpc ListenForBooks(stream QueryBooksRequest) returns (stream Book) {}

Usage with NodeJS

Refer to grpc-web-node-http-transport.

All Docs

@cobaltspeech/sdk-cubic@gitpod/local-app-api-grpcweb@gitpod/ide-metrics-api-grpcweb@gitpod/supervisor-api-grpcwebzoobc-sdk-jszoobcep3-ls-clientinjective-apisummer-solutions-api-service@corioders/stdcasperlabs-grpccasperlabs-sdkcasperlabsjs@alexey-ulashchick/dashboard-protos@pognetwork/champ-protocogmentmessina-sdkdreamstudio-wrappersecretjs-cjgssecretjs-hmtsome-chain-sdkstability-clientstability-client-maskstability-tsstateset-js@devvit/cli@dashevo/dapi-grpc@dimensiondev/onflow-protobuf@dimensiondev/onflow-sdkrpc_tsrtk-query-grpc-webreactrpcsocprox@daodiseomoney/daodiseo.proto@dcl/ion-sdk-js@dcl/voicequant-grpc-docsreact-im-viewsliver-scriptskyeye-svc-common-grpcopen-im-ioncarbon-js-sdk@bandprotocol/bandchain.jsceler-web-sdkceler-light-client@berty/grpc-bridgecitadel-svc-common-grpcpixui-custom-scrollbarpixui-sprite-maker@careerkarma/ion-sdk-js@chris.troutner/ipfs-grpc-client@classic-terra/terra.proto@certusone/wormhole-sdk-proto-web@chain.js/proto@cloud8little/latticexyz-cli@spacehq/mailbox@spacehq/storage@spacehq/utils@complyify/thebar@complyify/sdk@concha-network/cli@cogment/cogment-js-sdkprotowebjscos-grpc-js@corioders/jskit@coschain/cosjscbridge-web-widgetcbridge-widget@blocto/protobuf@bpiv400/terra.proto@codewritz/herajs-client@davmixcool/stability-ts@deltaswapio/deltaswap-sdk-proto-web@depyronick/stability-client@algo-foundry/messina-sdknonsimilique@5sim/hub-server-clientbandchain2.js@aitmed/aitmed-grpc-sdk@aitmed/aitmed-grpc-sdk-test@aitmed/crypto-sdk@aitmed/crypto-sdk-test@alephium/wormhole-sdk@andrew54068/sdksun-dd-cliflow-rtc@stemsdao/backend-client@forbole/cosmos-protobuf-js@farcaster/hub-web@lavanet/lava-sdk@konstellation/celestial@lacuna-tech/rpc_ts@lazycatcloud/lzc-apis@liuqiang1357/latticexyz-cli@portto/sdk@pognetwork/proto@routerprotocol/chain-api@routerprotocol/router-chain-sdk-ts@routerprotocol/sdk-ts@roomservice/ion-sdk-js
0.15.0

2 years ago

0.14.1

3 years ago

0.14.0

3 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.6

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.8.0

5 years ago