grpc.client
a simple NodeJS client for gRPC
api
const client = require('grpc.client')
- client(an optional {})
- type string, with the values
unary
andstream
,unary
is the default value - address string with the format
url:port
- credentials can use
credentials.createInsecure
or with certificates through an object { ca, key, client } and should be a Buffer - metadata set metadata that can be used in all calls, an array with { key: value }
- type string, with the values
methods
- service(service name - string, path to the protoFile - string)
- setMetadata(plain js object) to be used when needs to pass metadata to the server but the function doesn't send any data to the server
- end(err - Error object, res from the rpc server - depends of the proto/contract, metadata - plain js object)
grpc.client
will create dynamically the method or methods from the rpc methods list for a given service and protofile, check examples below
example
const client = // proto file/*syntax = "proto3"; package helloWorld; // The greeting service definition.service Greeter { // Sends a greeting rpc sayHello (HelloRequest) returns (HelloReply) {}} // The request message containing the user's name.message HelloRequest { string name = 1;} // The response message containing the greetingsmessage HelloReply { string message = 1;}*/ //// creating a static client// const greeter = greeter // no data sends to the server greeter