Router

use(middleware)

Use the given middleware function or object on this router.

   // middleware function
   router.use((req, res, next) => {console.log('Hello')});

   // middleware object
   router.use(new Middleware());

Parameters

middleware: Middleware | function, Middleware object or function

Returns: Router, for chaining

all(middleware)

Use the given middleware function or object on this router for all HTTP methods.

   // middleware function
   router.all((req, res, next) => {console.log('Hello')});

   // middleware object
   router.all(new Middleware());

Parameters

middleware: Middleware | function, Middleware object or function

Returns: Router, for chaining

method(uri, middleware)

Use the given middleware function or object, with optional uri on HTTP methods: get, post, put, delete... Default uri is "/".

 // middleware function will be applied on path "/"
 router.get((req, res, next) => {console.log('Hello')});

 // middleware object will be applied on path "/" and
 router.get(new Middleware());

 // middleware function will be applied on path "/user"
 router.post('/user', (req, res, next) => {console.log('Hello')});

 // middleware object will be applied on path "/user" and
 router.post('/user', new Middleware());

Parameters

uri: String, path

middleware: Middleware | function, Middleware object or function

Returns: Router, for chaining