Skip to content

Throttling Handler

Thiago Bustamante edited this page May 22, 2017 · 3 revisions

A Throttling Handler middleware is a function executed when the throttling max limit is exceeded. It receives the following parameters:

  • request: The request received by the Gateway from the user.
  • response: The response to be sent by the Gateway to the user.
  • next: The express next function, if you need to pass to the next middleware.

Each middleware must be defined on its own .js file.

Example:

/**
 * @param request The request received by the Gateway from the user.
 * @param response The response to be sent by the Gateway to the user.
 * @param next The [express](http://expressjs.com) next function, if you need to pass to the next middleware.
 */
module.exports = function (request, response, next) {
  response.format({
     html: function(){
        response.status(options.statusCode).end(options.message);
     },
     json: function(){
        response.status(options.statusCode).json({ message: options.message });
     }
  });
};

The above function is the default function used as handler for the throttling.

You can configure a Handler middleware through:

  • Admin Rest API: POST /midleware/throttling/handlers
  • SDK: sdk.middleware.addThrottlingHandler(name, fileName);
  • CLI: treeGatewayConfig middleware throttlingHandler -a <name> ./filename.js
Clone this wiki locally