Created
December 11, 2019 13:55
-
-
Save robintan/5b80d98a59f338799b6727e901881bc8 to your computer and use it in GitHub Desktop.
Fastify - Number validator 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
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