Making gRPC services easier to use in typescript.
yarn add grpcd
import { server, Service, RPC, Errors } from 'grpcd';
import { HelloParameters, HelloResponse, ErrorResponse, ErrorParameters } from './hello_pb';
@Service(__dirname + '/hello.proto')
class HelloService {
private counter = 1;
@RPC()
public hello(params: HelloParameters.AsObject): HelloResponse.AsObject {
return {
response: `Hello ${params.name} number ${this.counter++}`
};
}
// Throw a grpc error
@RPC()
public error(params: ErrorParameters.AsObject): ErrorResponse.AsObject {
throw new Errors.NotFoundError("Greeting was not found!!");
}
}
server.addService(new HelloService());
server.start();
- Service decorator
- RPC decorator
- Async calls
- Throwing errors
- gRPC streaming
For easier source file and dependency management for gRPC checkout protobox.