grpc-web-service-generator
v0.2.3
Published
gRPC-Web Service Generator
Downloads
17
Readme
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();
}
});