šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

grpc-base-client

Package Overview
Dependencies
Maintainers
8
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-base-client

This project is a Library base for construct gRPC clients

2.3.0
latest
Source
npm
Version published
Weekly downloads
60
200%
Maintainers
8
Weekly downloads
Ā 
Created
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

grpc

FAQs

Package last updated on 16 Dec 2023

Did you know?

Socket

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