Controller

new Controller(name)

Controller class

Parameters:
NameTypeDescription
namestring

Name of the Controller

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.get('/', [], (req, res) => {
    res.json(1000, {
        hello: 'world!'
    });
});

Members

name :string

Controller name used for internal logs

Type:
  • string
Since
  • 1.0.0
Author
  • Glenn de Haan

router :Router

Express router instance used by the Express server

Type:
Since
  • 1.0.0
Author
  • Glenn de Haan

routes :array.<object>

Array of routes which to implement within Express

Type:
  • array.<object>
Since
  • 1.0.0
Author
  • Glenn de Haan

Methods

copy(path, middlewares, handler)

Add a COPY route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.copy('/', [], (req, res) => {
    // Custom handler code here
});

delete(path, middlewares, handler)

Add a DELETE route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.delete('/', [], (req, res) => {
    // Custom handler code here
});

get(path, middlewares, handler)

Add a GET route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.get('/', [], (req, res) => {
    // Custom handler code here
});

Add a HEAD route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.head('/', [], (req, res) => {
    // Custom handler code here
});

lock(path, middlewares, handler)

Add a LOCK route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.lock('/', [], (req, res) => {
    // Custom handler code here
});

options(path, middlewares, handler)

Add a OPTIONS route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.options('/', [], (req, res) => {
    // Custom handler code here
});

patch(path, middlewares, handler)

Add a PATCH route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.patch('/', [], (req, res) => {
    // Custom handler code here
});

post(path, middlewares, handler)

Add a POST route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.post('/', [], (req, res) => {
    // Custom handler code here
});

purge(path, middlewares, handler)

Add a PURGE route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.purge('/', [], (req, res) => {
    // Custom handler code here
});

put(path, middlewares, handler)

Add a PUT route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.put('/', [], (req, res) => {
    // Custom handler code here
});

unlock(path, middlewares, handler)

Add a UNLOCK route to the Controller

Parameters:
NameTypeDescription
pathstring

A path to bind the handler function to

middlewaresarray.<function(*, *, *)>

An array of Middlewares

handlerfunction

A handler function that handles the incoming HTTP request

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Controller} = require('@neobeach/core');
const controller = new Controller('IndexController');

controller.unlock('/', [], (req, res) => {
    // Custom handler code here
});