0.5.1 • Published 3 years ago

grpc-modern v0.5.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

gRPC Modern

codecov npm.io npm.io npm.io npm.io

Makes grpc clients(@grpc/grpc-js, grpc) fit in modern JavaScript(TypeScript) environment.

  • Change callback interface with Promise
  • Change new + set interface with object literal

Installation

$ yarn add grpc-modern

# peer dependencies
$ yarn add @grpc/grpc-js google-protobuf
$ yarn add --dev @types/google-protobuf

# or
$ yarn add grpc google-protobuf
$ yarn add --dev @types/google-protobuf

Usage

/**
 * without `grpc-modern`
 */
import * as grpc from "@grpc/grpc-js";
import { GetSomethingReq, SomethingClient } from "../stubs/something/...";

const client = new SomethingClient(
  "example.com:80",
  grpc.credentials.createInsecure()
);

const req = new GetSomethingReq();
req.setId("...");
req.setSomeOption(false);

client.getSomething(req, (error, response) => {
  console.log(response);
});

/**
 * with `grpc-modern`
 */
import { makeModernClient } from "grpc-modern";

const client = makeModernClient(SomethingClient, {
  address: "example.com:80",
  credential: grpc.credentials.createInsecure(),
});

const response = await client.getSomething(
  set(GetSomethingReq, {
    id: "...",
    someOption: false,
  })
);

/**
 * or you can use with `grpc`
 */
import * as grpc from "grpc";

const client = makeModernClient(SomethingClient, {
  address: "example.com:80",
  credential: grpc.credentials.createInsecure(),
});

const response = await client.getSomething(
  set(GetSomethingReq, {
    id: "...",
    someOption: false,
  })
);
0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.5.1

3 years ago

0.4.2

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago