Created
December 8, 2015 23:10
-
-
Save thebergamo/cf26fce44a9d00706a25 to your computer and use it in GitHub Desktop.
Route Todo example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Controller = require('../controllers/todo'); | |
exports.register = (server, options, next) => { | |
// instantiate controller | |
const controller = new Controller(options.database); | |
server.bind(controller); | |
server.route([ | |
{ | |
method: 'GET', | |
path: '/todo/{id}', | |
config: { | |
handler: controller.get, | |
validate: { | |
params: { | |
id: Joi | |
.string() | |
.alphanum() | |
.regex(/^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/i, '_id') | |
.required() | |
} | |
} | |
} | |
}, | |
{ | |
method: 'POST', | |
path: '/todo', | |
config: { | |
handler: controller.create, | |
validate: { | |
payload: { | |
name: Joi | |
.string() | |
.min(1) | |
.max(30) | |
.trim() | |
.required(), | |
checked: Joi | |
.boolean() | |
.default(false) | |
.optional() | |
} | |
} | |
} | |
} | |
]); | |
next(); | |
}; | |
exports.register.attributes = { | |
name: 'todo-route', | |
version: '1.0.0' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment