Reputation: 32726
How to validate an optional parameter using hapi and joi
path: '/users/{limit?}',
limit is optional but if present should be an integer.
Upvotes: 2
Views: 2917
Reputation: 42058
You can use Joi.number().integer()
in the validate
section:
server.route({
method: 'GET',
path:'/users/{limit?}',
config: {
validate: {
params: {
limit: Joi.number().integer()
}
}
},
handler: function (request, reply) {
reply('ok');
}
});
Upvotes: 7