You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common use-case for validation is checking that a request body is valid. This module should expose a helper to make that process easy to do inline when defining an express route.
Something like:
route.post('/login',Validate.middleware({username: {type: String,required: true,minLength: 8,maxLength: 50},password: {type: String,required: true,minLength: 12maxLength: 128}),(req,res)=>{letrequestBody=req.validatedBody;// Only gets here if body passed validation});
// internal logic something likereq.validatedBody=validator;// or if you want a POJO (maybe make this an option, or inverse of this is an option?)req.validatedBody=validator.toObject();try{validator.validate()}catch(e){returnres.status(400).json({error: e.firstError()});}returnnext();
I believe it would be best to have it reject requests by default, and you could would specify an option to have it pass just the validated instance through instead.
It would also be nice if you could pass in options, maybe something to indicate what status to use for rejections, or maybe what format the error response should be in, maybe an error response formatting function?
The text was updated successfully, but these errors were encountered:
A common use-case for validation is checking that a request body is valid. This module should expose a helper to make that process easy to do inline when defining an express route.
Something like:
I believe it would be best to have it reject requests by default, and you could would specify an option to have it pass just the validated instance through instead.
It would also be nice if you could pass in options, maybe something to indicate what status to use for rejections, or maybe what format the error response should be in, maybe an error response formatting function?
The text was updated successfully, but these errors were encountered: