Validating package payload
We talked about validating incoming payload which was basically a client’s input in a JSON format.
We were wondering if there’s one proper place to validate requests in web applications.
Multiple ideas appeared so I’d like to present them here.
@iltar It's documented here In my case, it's for an API, so I added a custom Constraint Violation List Normalizer Ah I thought you meant that it was a completely new feature, but this issue is to make sure that you can manually set the payload as well as via annotations, right? By default this array should be empty , so it's optional.Payload is an interface, we can provide an implementation of this interface as an element for 'payload' to provide some additional metadata information in a typed-safe way (as compare to some string literal) or we can even invoke some dynamic code with it. This example idea is taken from the spec documents This example shows how payload can be used to invoke some dynamic code using reflection.In case the validation doesn’t pass successfully, you’ll receive the aforementioned as individual fields.We hope you enjoyed this guide on payload validation and take away the insights on how to improve your code by validating fields as early as possible.
Search for validating package payload:
If you didn’t define any validation, hapi skips this step and proceeds with the route handler.