@telidoo/grpc-lib
v1.0.2
Published
A wrapper around grpc to make using it more comfrotable. Based on [grpc-kit](https://github.com/YoshiyukiKato/grpc-kit) with extra features like promisified client requests.
Downloads
4
Readme
@telidoo/grpc-lib
A wrapper around grpc to make using it more comfrotable. Based on grpc-kit with extra features like promisified client requests.
Usage
Install:
npm install @telidoo/grpc-lib grpc @grpc/proto-loader
Proto:
syntax = "proto3";
package greeter;
service Greeter {
rpc Hello(RequestGreet) returns (ResponseGreet);
}
message RequestGreet {
string name = 1;
}
message ResponseGreet {
string message = 1;
}
Server:
const { createServer } = require("@telidoo/grpc-lib");
const server = createServer();
server.use({
protoPath: "./protos/greeter.proto",
packageName: "greeter",
serviceName: "Greeter",
routes: {
hello: async (call) => {
return { message: `Hello, ${call.request.name}` };
}
},
options: {}
});
server.listen("0.0.0.0:3333");
Client:
const { createClient } = require("@telidoo/grpc-lib");
const client = createClient({
protoPath: "./protos/greeter.proto",
packageName: "greeter",
serviceName: "Greeter",
options: {}
}, "localhost:3333");
(async () => {
const { message } = await client.hello({ name: "Jack" });
console.log(message);
})();
The options are for the protobuf loader, documentation can be seen here: https://github.com/grpc/grpc-node/tree/master/packages/proto-loader