Socket
Socket
Sign inDemoInstall

grpc-base-client

Package Overview
Dependencies
121
Maintainers
8
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    grpc-base-client

This project is a Library base for construct gRPC clients


Version published
Weekly downloads
9
decreased by-68.97%
Maintainers
8
Install size
513 kB
Created
Weekly downloads
 

Readme

Source

Actions Status Actions Status Actions Status Test Coverage Maintainability npm version

  • This library auto-apply promise into Unary calls
  • This library implements a consistent Connection Pool with a Round-Robin strategy auto manageable for its instance or new instances;
  • It's supports gRPC and gRPC-js implementations;

How to Install

npm i @codibre/grpc-base-client

How to Use


import { Client as gRPCCLient } from '@codibre/grpc-base-client';

interface Health {
	Check(props: { service: string }): Promise<any>;
}

const grpcCLient = new gRPCCLient<Health>({
	namespace: 'abc.def',
	protoFile: 'health-check.proto',
	url: 'test.service',
	maxConnections: 2,
	service: 'Health',
	secure: true,
});



await grpcCLient.getInstance().Check({service: 'foo'}); // { status: 'SERVING' }

How to retrieve client through reflection

Is your GRPC servers implements GRPC Reflection Protobol, then you don't need to have a copy of the proto client side and can just get it using it! This package implements a method to create the client using this feature that can be easily used like this:

import { Client as gRPCCLient } from '@codibre/grpc-base-client';

interface Health {
	Check(props: { service: string }): Promise<any>;
}

const grpcCLient = gRPCCLient.getByReflection<Health>({
	namespace: 'abc.def',
	url: 'test.service',
	maxConnections: 2,
	service: 'Health',
	secure: true,
});

await grpcCLient.getInstance().Check({service: 'foo'}); // { status: 'SERVING' }

Notice that you don't inform the protoFile in this call, as it is not needed. Also, this method don't offers a legacy library switch, as it'll only work with the new @grpc/grpc-js library.

If you want to find out how to implement it on your server, it really pretty easy! Just take a look at the official implementation for NodeJs: @grpc/reflection. If you're using NestJs, another option is nestjs-grpc-reflection, although the official one is preatty straight forward to use alongside with nestjs too.

To use getByReflection, you need to install two optional libraries:

License

Licensed under MIT.

Keywords

FAQs

Last updated on 16 Dec 2023

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