When constructing a routing handler the following methods/aliases are supported which can be used interchangeably when defining Route or Resource handlers.
| Handler Method | Alias |
|---|---|
| get | index |
| post | submit |
| put | create |
| patch | update |
| delete | N/A |
// .. appName/src/routes/foo.js'use strict';// Load module.constcontentTypeHeader=require('middleware/ContentTypeHeader');/** * @export {Object} */module.exports={middleware: [contentTypeHeader],// Locally scoped to /api/foo/** * GET /api/foo */index(req,res){res.status(200).send('Lambda, Lambda, Lambda');},/** * PUT /api/foo */create(req,res){res.status(201).send();},/** * PATCH /api/foo */update(req,res){res.status(204).send();},/** * DELETE /api/foo */delete(req,res){res.status(410).send();},/** * POST /api/foo */submit(req,res){res.status(200).send();}};// .. appName/src/routes/foo/bar.js'use strict';/** * @export {Object} */module.exports={resource: true,// Everything is a resource./** * GET /api/foo/bar/<resourceId> */get(req,res,id){res.setHeader('Content-Type','application/json');res.status(200).json({and: 'Omega Mu'});},/** * PUT /api/foo/bar/<resourceId> */put(req,res,id){res.status(201).send();},..};// .. appName/src/routes/foo.js'use strict';/** * @export {Object} */module.exports={resource: ['put'],// Limit to resource./** * GET /api/foo */index(req,res){res.setHeader('Content-Type','text/html');res.status(200).send('Lambda, Lambda, Lambda');},/** * PUT /api/foo/<resourceId> */put(req,res,id){res.setHeader('Content-Type','application/json');res.status(200).json({and: 'Omega Mu'});},..};When using an explicit Promise that returns a promised event, always declare your handler method as async function (see examples below).
// .. appName/src/routes/foo.js'use strict';/** * @export {Object} */module.exports={resource: ['get','patch'],/** * GET /api/foo */asyncindex(req,res){res.setHeader('Content-Type','text/html');res.status(200).send('Lambda, Lambda, Lambda');},/** * GET /api/foo/<resourceId> */asyncget(req,res,id){returnasyncOperation(id).then(function(result){res.setHeader('Content-Type','text/html');res.status(200).send(result||'No result');}).catch(function(){res.status(500).send();});},/** * PATCH /api/foo/<resourceId> */asyncpatch(req,res,id){try{constresult=awaitasyncOperation(id);res.setHeader('Content-Type','text/html');res.status(200).send(result||'No result');}catch(err){res.status(500).send();}},..};