I am trying to strike a perfect balance between validation input on a model level (Sequelize, Mongoose models etc. ) and validating input with route middleware (express-validator etc.).Take email as input and a POST to create a user for example, I can see two approaches:Use middleware to validate presence of email, allow Model validation and regex to reject the email if it is not formatted correctlyValidate email presence and format as soon as possible with route middleware, use model validation as an extra safety net, if somehow the incorrectly formatted email was passed through by the validator for some reasonWhat is your preference and why? How much should the route validators do? Should the do absolutely all the validation before the date even get to the model for creation?My initial thought were to allow models to perform all the validation that they can do, and middleware to check presence, nullability of the input vars, however I thought the performance of the db might be hit with the model validation (not sure if that is true)
Submitted September 05, 2020 at 11:21AM by CommercialBuilder99
No comments:
Post a Comment