-
-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return validation json response #1174
Conversation
I'm a bit confused here and was wondering if I might get a hand? After trying to implement this pattern for my own type and route, I copied the example code and brought it into my project, and it doesn't compile:
Any thoughts on what I might be missing? |
I figured it out: I was running |
Previously, the controller did not support automatic validation of POST parameters. Validation was done manually after deserialization using the serde_json library. For instance, the developer would create a struct, add validation rules using the Validate trait, and manually handle the validation errors in the controller.
New Implementation:
The updated implementation introduces a
JsonValidate
andFormValidate
and with messages response:JsonValidateWithMessage
andFormValidateWithMessage
extractors, which automatically handles validation and returns a JSON response for validation errors. This eliminates the need for manual validation logic in the controller.If validation fails, JsonValidate automatically returns a structured JSON response like the following: