4.0.0 • Published 8 years ago

grpc.client v4.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

grpc.client

a simple NodeJS client for gRPC


Build StatusCoverage StatusISC LicenseNodeJS

JavaScript Style Guide

api

const client = require('grpc.client')

  • client(an optional {})
    • type string, with the values unary and stream, 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 }

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 = require('grpc.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 greetings
message HelloReply {
  string message = 1;
}
*/

client()
  .service('Greeter', protos.helloWorld)
  .sayHello({ name: 'Scaramouche' })
  .end((err, res, metadata) => {
    if (err) {
      // do something
    }

    console.log(res)// will print { message: 'Hello Scaramouche' }
  })

//
// creating a static client
//

const greeter = client({ metadata: { xp: 'to' } })

greeter
  .service('Greeter', protos.helloWorld)
  .sayHello({ name: 'Scaramouche' }, { 'request-id': 12345 })
  .end((err, res, metadata) => {
    if (err) {
      // do something
    }

    console.log(res)// will print { message: 'Hello Scaramouche' }
  })

// no data sends to the server

greeter
  .service('Greeter', protos.something)
  .something()
  .setMetadata({ 'request-id': 12345 })
  .end((err, res, metadata) => {
    //
  })

ISC License (ISC)

4.0.0

8 years ago

3.2.1

8 years ago

3.1.1

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago

0.0.0

8 years ago