Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ges

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ges

gRPC experimental server that support koa-like interceptor

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by133.33%
Maintainers
1
Weekly downloads
 
Created
Source

grpc-experimental-server

gRPC experimental server that supports koa-like interceptors

Usage

npm i ges grpc
import ExperimentalServer from 'ges';

const server = new ExperimentalServer();

server.addService(/* ... */);

// add interceptor
server.use(async (context, next) => {
  // preprocess
  const start = Date.now();
  try {
    await next();
  } finally {
    // postprocess
    const costtime = Date.now() - start;
    console.log('costtime is', costtime);
    console.log('unary response is ', context.response);
  }
});

serer.bind(/* ... */);
server.start();

gRPC has 4 kinds of call:

handle typerequest is stream or notresponse is stream or not
handleUnaryCall
handleClientStreamingCall
handleServerStreamingCall
handleBidiStreamingCall

Context

  • call current gRPC call
  • definition the method definition of current call
  • response response if response is not stream
  • onFinished(...) you can listen on call finish event, no matter response of current call is stream or not. So you don't need to care about what kind is the call. It is very useful to do something like tracing, logging

Notes

  • await next() would wait the call to be finished if response is not stream.

Keywords

FAQs

Package last updated on 22 Oct 2020

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc