To build a gRPC package, you first have to create a *.proto
file. More on that in the proto section (coming soon) and on the official protocol buffer page.
Build starts with a *.proto
file. Take the following *.proto
file as an example.
package myPackage
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
From there, you will likely want to access the Services on your .proto packaged object. These can be accessed as top level properties on the object, matching the name inside of your proto file. Here's an example of what that would look like.
const { build } = require( 'firecomm' );
const proto_path = require( '../some/proto/path' );
const package = build( proto_path, { bytes: String } );
// Packaged service
const service = package.Greeter
// export for use in other files
module.exports = {
service,
package
};