I want to build an ApiClient that transforms API responses into a Monad.
Normally a successful response looks like this:
{
ok: true,
data: { ... },
headers,
}
And the error response like this:
{
ok: false,
error: { ... },
headers,
}
My first approach was using the Either monad so I no longer need the ok field. The Left value would be error and the Right one data. But what should I do with headers and other meta information of the response?
Most of the time I do not care that much about the meta information of an api response. I like how the Either monad helps to focus my code in the most important value. However now I must hack my data and error fields.
Is there another monad suitable for these cases? Or is this problem solved by some other approach?