RequestValidation

A plugin that checks a request body using Validator. Example:

install(RequestValidation) {
validate<String> {
if (!it.startsWith("+")) ValidationResult.Invalid("$it should start with \"+\"")
else ValidationResult.Valid
}
}
install(StatusPages) {
exception<RequestValidationException> { call, cause ->
call.respond(HttpStatusCode.BadRequest, cause.reasons.joinToString())
}
}