Monad for API response
I want to create an ApiClient that converts API responses to Monad.
Usually a successful response looks like this:
{
ok: true,
data: { ... },
headers,
}
And an error response like this:
{
ok: false,
error: { ... },
headers,
}
My first approach used the Libo monad , so I no longer need the ok field . The value of the left would be a mistake, and Right - one. But what should I do with headers and other meta information in the response?
Most of the time I care about the api response meta information. I love how nun Either helps me focus my code on the most important meaning. However, now I have to hack my data and error fields.
Is there another monad suitable for these cases? Or is this problem solved by some other approach?
+3
source to share