@brandonxiang/ges
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

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 type request is stream or not response 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.

Package Sidebar

Install

npm i @brandonxiang/ges

Weekly Downloads

0

Version

3.0.0

License

ISC

Unpacked Size

11.2 kB

Total Files

5

Last publish

Collaborators

  • brandonxiang