API Middleware

Let’s see why we need a communication middleware and understand what problems it addresses.

A quick glance at the previous two action creator examples reveals that there are only two differences between the functions: the URL and the action that gets dispatched when data is successfully fetched.

In the spirit of generality, we can create an abstract layer to handle network requests and only pass it the url and onSuccess parameters. But using a shared function or library does not fully solve all the problems mentioned earlier. Our action creators will still be asynchronous, which means they’ll be harder to test and more difficult to debug using the regular Redux debug flow of monitoring all actions dispatched to the store.

Get hands-on with 1200+ tech skills courses.