validate function

RequestHandler validate (
  1. Validator validator,
  2. {String errorMessage: 'Invalid data.'}

Validates the data in req.bodyAsMap, and sets the body to filtered data before continuing the response.


RequestHandler validate(Validator validator,
    {String errorMessage = 'Invalid data.'}) {
  return (RequestContext req, res) async {
    await req.parseBody();
    var result = await asyncApplyValidator(validator, req.bodyAsMap,;

    if (result.errors.isNotEmpty) {
      throw AngelHttpException.badRequest(
          message: errorMessage, errors: result.errors);


    return true;