I am writing a JSON RESTFul service with Yesod and need to validate requests. I can not use Yesod.Form for it because the service accepts JSON. I like the validation method, but I havenโt found such an approach in Haskell.
Is there a best practice for checking that would allow you to respond to messages with structured errors, for example:
Request
{ "birthDate": "2017.07.14", "count": "three", "kind": "baz", "entity": { "id": -1 } }
Answer
{ "errors": { "birthDate": "Date should be less than 2014.05.25", // current date "count": "should be a number", "kind": "must be one of [foo, bar]", "entity": { "id": "Entity with id -1 not found" } } }
json rest haskell yesod
Andrey Kuznetsov
source share