As in a simpler example or a simpler way of achieving the same thing? If it's the latter, and you know how to do it, I'd love to receive some guidance and I refactor the article's example.
Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
This will resolve with a Js.Promise.t(Belt.Result.t(response, error)) meaning the service didn't return an error message but the JSON may or may not have parsed successfully, or reject with your exception containing the service error message.
As in a simpler example or a simpler way of achieving the same thing? If it's the latter, and you know how to do it, I'd love to receive some guidance and I refactor the article's example.
Check out github.com/ryb73/ppx_decco , it's a JSON codec PPX. It should work something like this:
Now it can decode a
Js.Json.t
that you got fromFetch.Response.json
:This will resolve with a
Js.Promise.t(Belt.Result.t(response, error))
meaning the service didn't return an error message but the JSON may or may not have parsed successfully, or reject with your exception containing the service error message.This syntax looks much cleaner ๐คฉ. I will give it a try soon with the Request module and comment about it in this part of the article. Thank you!