Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Created December 8, 2015 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebergamo/cf26fce44a9d00706a25 to your computer and use it in GitHub Desktop.
Save thebergamo/cf26fce44a9d00706a25 to your computer and use it in GitHub Desktop.
Route Todo example
'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