Socket
Socket
Sign inDemoInstall

grpc.client

Package Overview
Dependencies
94
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    grpc.client

a simple client for gRPC


Version published
Weekly downloads
14
increased by1300%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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)

Keywords

FAQs

Last updated on 18 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc