Skip to content

Instantly share code, notes, and snippets.

@robintan
Created December 11, 2019 13:55
Show Gist options
  • Save robintan/5b80d98a59f338799b6727e901881bc8 to your computer and use it in GitHub Desktop.
Save robintan/5b80d98a59f338799b6727e901881bc8 to your computer and use it in GitHub Desktop.
Fastify - Number validator example
module.exports = [{
method : 'GET',
url : '/checkNumbers',
handler : async (req, reply) => ({ message : 'Yay! Success!, success : true }),
schema : {
querystring : {
type : 'object',
properties : {
positive_number : {
type : 'number',
validator : [(data) => data > 0, _ => 'must be positive number'],
},
negative_number : {
type : 'number',
validator : (data) => data < 0, // will use default message
},
},
required: ['positive_number', 'negative_number'],
},
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment