frontexpress/docs/router.md
2016-07-23 10:48:26 +02:00

1.5 KiB

Router

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

Router.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

Router.get(uri, middleware), Router.post(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