January 23, 2019
I don’t like the idea about middlewares. It implies that I have to keep up a
queue of entities liyng around somewhere in the memory waiting for a particular
scenario to occur (like receiving a 400
response and performing a logout
action). This seems to be the total opposite to ephemeral and short living
functions that do their thing then go out of the way. It’s just too much of a
mental burden to me.
In this post I’d like to propose a simpler alternative. In fact, we are not
going to reinvent the wheel at all by creating one more API for firing up
requests (probably because we already have too much of them). Instead, we’ll
rely on the very popular & battle tested
Fetch API. The
proposed solution will be a simple function that has the exact same API as
fetch()
, but with some modified behavior.