Created
November 7, 2017 15:27
-
-
Save dgolant/ca3c4c66f529f3c15d7cee47dd0418f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
app.post(‘/user/links’, Celebrate({ | |
body: Joi.object().keys({ | |
important_value: Joi.string().required(), // look, type enforcement! | |
data1: Joi.number().integer(), | |
data2: Joi.string().default(‘admin’) // hey, and defaults! | |
}), | |
query: { | |
token: Joi.string().token().required() // you can use one object to | |
// validate body, query, | |
// and params all at once | |
} | |
}), (req, res) => { | |
/* Here we do whatever the route is | |
actually supposed to do, | |
because Celebrate will automatically res.status(400).send() | |
an informative message | |
if the validation fails | |
*/ | |
}); | |
app.use(Celebrate.errors()); // taken and modified from the Celebrate docs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment