Validating query strings


#1

I’m trying to validate query strings according to this JSONAPI specification:

If a server is unable to identify a relationship path or does not support inclusion of resources from a path, it MUST respond with 400 Bad Request.

What is a good way to validate query strings (or best practices)? Seems like the validator only validates against the request body. Currently just calling an instance method inside a controller doesn’t seem like a scalable solution and goes against the DRY principle.


#2

You can define your own custom data object. More in docs https://adonisjs.com/docs/4.1/validator#_custom_data_object


#3

Perfect! I should’ve read the docs more carefully. Thank you @virk!


#4

@virk I ended up creating a PR on indicative repo that should help others implement this part of JSONAPI validation (which requires checking if array1 is a subset of array2): https://github.com/poppinss/indicative/pull/203