GrpcService

GrpcService

GrpcService is the base class for your service

  • You need to extend this class and just implement class functions (Exposed functions must be async)
  • Methods starts with _ underscore will be ignored and considered private, so it will not be exposed into your gRPC service

Constructor

new GrpcService(options)

Source:
Parameters:
Name Type Description
options object
Name Type Attributes Description
proto string

Service protobuf schema

hooks object <optional>

Service hooks, helper functions to be attached to request context (ctx) object, which will be passed to callee function

middlewares Array.<object> <optional>

Service middlewares, functions that will be execute in order before service function, and will have the request context as argument

loaderOptions object <optional>

Protobuf loader configurations

onError function <optional>

An error handler for service function call

Methods

(private) _applyHooks(context)

Apply hook functions to request context object

Source:
Parameters:
Name Type Description
context

(private) _applyMiddlewares(context)

Cycle through all middleware functions in order, and call it against request context

Source:
Parameters:
Name Type Description
context

descriptor() → {object}

Get service descriptor for provided protobuf schema (Called by GrpcServer during service creation process)

Source:
Returns:
Type:
object

Service descriptor

implementation() → {object}

Get service implementation for provided protobuf schema (Called by GrpcServer during service creation process)

Source:
Returns:
Type:
object

Service implementation, which will be provided by user child class