grpc-web-service-generator

0.2.3 • Public • Published

gRPC-Web Service Generator

Wrapper service over base grpc-web.

Installation

$ yarn add grpc-web-service-generator

For server-side

$ yarn grpc-web-service-generator --proto-file=./proto/rpc.proto --output-dir=./proto --skip-grpc-service

For client-side

$ yarn grpc-web-service-generator --proto-file=./proto/rpc.proto --output-dir=./services/GrpcService

Parameters

  • --proto-file - path to main proto.
  • --output-dir - dir path for generated code.
  • --skip-grpc-service - disabling generation GrpcService (special for server-side)

Usage (client-side)

// rpc.proto

syntax = "proto3";

package RpcPackage;

service TodoService {
  rpc AddTodo() returns () {}
}

Version <= 0.1.6

import { GrpcService } from './GrpcService';

const grpcService = new GrpcService('http://localhost:8080');

grpcService.TodoService.AddTodo({}).then(response => ...)

Version >= 0.1.7 (Support for multiple packages)

import { GrpcService } from './GrpcService';

const grpcService = new GrpcService('http://localhost:8080');

grpcService.RpcPackage.TodoService.AddTodo({}).then(response => ...)

Interceptors

const updateGrpcServiceAccessToken = async () => {
  storedAccessToken = await grpcService.AuthService.GetAccessToken();
  console.log('updateGrpcServiceAccessToken', storedAccessToken);
  grpcService.setAccessToken(storedAccessToken);
};

grpcService.interceptors.errors.push((e) => {
  if (e === 'INVALID_TOKEN') {
    return updateGrpcServiceAccessToken();
  } else {
    return Promise.resolve();
  }
});

Readme

Keywords

Package Sidebar

Install

npm i grpc-web-service-generator

Weekly Downloads

3

Version

0.2.3

License

MIT

Unpacked Size

48.5 kB

Total Files

17

Last publish

Collaborators

  • quarrant