Validating package payload

Validating incoming user data as early will keep your code base clean and small.You don’t need to perform the validation steps yourself within the route handler. 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.

validating package payload-53

If validation fails, hapi will reply with a detailed boom error object including the reason why validation failed.

I'm still not sure what the point is of severity though, sure you get a warning in your form, but you'll never see it if the form was valid.

Recently, during a pair programming session, I had a really interesting discussion.

We validate if incoming request contains all parameters we provided in these options. we may want that user always provide when listing some content to avoid fetching all records from our DB.

In case all keys are provided we respond with success, otherwise we return “bad request (400)” response.

Leave a Reply