Skip to content

Releases: Reaverart/redux-callapi-middleware

Simple typed actions

06 Jun 13:51
Compare
Choose a tag to compare

Sometimes we dont want to handle all the request , success , failure action types or reducer is simple enough to handle all of them at once, so with new release you can use simple typed action:

[CALL_API]: {
   type: YOUR_ACTION_TYPE,
   ...
}

in result it will dispatch following actions:

{
   type: YOUR_ACTION_TYPE,
   [CALL_API_PHASE]: REQUEST || SUCCESS || FAILURE ,
}

where CALL_API_PHASE - is a js Symbol you can import from library and phases are constants library also exports. I.e. if in reducer you need to check phase then:

import { CALL_API_PHASE, callApiPhases } from `redux-callapi-middleware`;
// reducer.js
(state, action) => {
   ...
   case YOUR_ACTION_TYPE:
      const phase = action[CALL_API_PHASE];
      if (phase === callApiPhases.REQUEST) {
         // handle request
      } else if (phase === callApiPhases.SUCCESS) {
         // handle success
      } else if (phase === callApiPhases.FAILURE) {
         // handle failure
      }
   ...
}

Remove fetch dependency

02 Apr 15:12
Compare
Choose a tag to compare

Breaking changes

No more fetch dependency, instead of optional interceptors you need to pass your own fetch function named callApi that should return a Promise. This way is more flexible in part that your project might already have own fetch implementation and it might be any lib like axios or isomorphic-fetch or anything.

0.3.0

08 Dec 15:00
Compare
Choose a tag to compare

Sometimes it needs to start new middleware chain instead of continue current. So now middleware uses dispatch instead of next to dispatch action types.
So now you might chain your api calls! Just return another call api action from action creator!

Batch multiple requests and response interceptors!

06 Feb 10:57
Compare
Choose a tag to compare

✨ batch requests is out! Now it allows to fetch multiple requests at once!
✨ response interceptors!

Breaking changes:

  • createMiddleware now receives responseSuccess and responseFailure interceptors, see create middleware in readme