Module: restapi

The restapi module of the webserver adapter.

This module implements the handler functions that serve the incoming endpoint calls

Used only internally by the adapter.

Methods

(static) callMessagingForwarder(container, endpoint, req, res, next)

Call the MESSAGING forwarder service function

Executes a JSON-RPC request via messaging, that puts the request to the topic named generated by the <topicPrefix>.<endpoint.method>_<endpoint.uri> pattern.
The message also containts the method and uri properties as well as
the normalized version of the request object and the endpoint descriptor.

The function will respond the result of the JSON-RPC call, and finally calls the next() middleware step.

Parameters:
Name Type Description
container Object

The container context

endpoint Object

The non-static endpoint descriptor object

req Object

The request object of the API call.

res Object

The response object of the API call.

next function

The error-first callback, to call the next middleware in the chain.

(static) callServiceFuntion(container, endpoint, req, res, serviceFun, next)

Call the service function

Executes the call of the service function with the request and response parameters according to the endpoint description.
The service function gets the request object and the endpoint descriptor. It must return a Promise, that will be resolved to a normal response.
If the result of the service function is rejected it will response with error.
Finally calls the next() middleware step.

Parameters:
Name Type Description
container Object

The container context

endpoint Object

The non-static endpoint descriptor object

req Object

The request object of the API call.

res Object

The response object of the API call.

serviceFun function

The service function, that must return a Promise.

next function

The error-first callback, to call the next middleware in the chain.

(static) setEndpoints(container, server, endpoints)

Setup the non-static endpoints of the web server

Parameters:
Name Type Description
container Object

The container context

server Object

The server object, that the endpoints will be added to

endpoints Array

The array of endpoint descriptor objects

(inner) getTopicName(endpoint) → {String}

Make a valid topic name out of the endpoint

Parameters:
Name Type Description
endpoint Object

The endpoint descriptor object

Returns:
  • A valid messaging topic name
Type
String

(inner) mkHandlerFun(container, endpoint, req, res, next)

Make handler function that serves the incoming API calls

This is a currying function, that returns with a function which will handle the given API call.

Parameters:
Name Type Description
container Object

The container context

endpoint Object

The non-static endpoint descriptor object

req Object

The request object of the API call.

res Object

The response object of the API call.

next function

The error-first callback, to call the next middleware in the chain.