grpc-modern
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

gRPC Modern

codecov

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,
  })
);

/grpc-modern/

    Package Sidebar

    Install

    npm i grpc-modern

    Weekly Downloads

    11

    Version

    0.5.1

    License

    Apache-2.0

    Unpacked Size

    25.8 kB

    Total Files

    27

    Last publish

    Collaborators

    • tonyfromundefined