Redux Axios Middleware is a Redux middleware designed to streamline data fetching using the popular Axios HTTP client within Redux applications. The current stable version is 4.0.1, with the last major release (v4.0.0) in March 2017, indicating a very slow release cadence, suggesting it's feature-complete or in maintenance mode rather than active development. Its key differentiators include directly integrating Axios request configurations into Redux actions, managing the full lifecycle of HTTP requests (start, success, error) with configurable action types and suffixes, and enabling promise chaining on dispatched actions for sequential logic or advanced error handling. It also supports defining and using multiple Axios clients for different APIs within a single Redux store.
npm install redux-axios-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up `redux-axios-middleware` with a Redux store, configuring an Axios client, dispatching an action with a `payload.request` definition, and handling the resulting promise for success or failure.
Update interceptor functions to call `getSourceAction()` instead of directly using `action` parameter to retrieve the original action object.
Review your action types and reducers that handle actions dispatched by the middleware. Adjust them to match the new default prefixing or explicitly configure `successSuffix` and `errorSuffix` in the middleware options.
Ensure all actions intended for the middleware include `{ payload: { request: { url: ..., method: ... } } }`.Consistently use one pattern for defining action types. For fine-grained control, use the `types` array. Understand how suffixes (`_SUCCESS`, `_FAIL`) are applied when using a single `type` string.
Ensure an initialized Axios instance is passed to the middleware: `axiosMiddleware(axios.create(...))`.
Add either a `type: 'MY_ACTION_TYPE'` or `types: ['MY_REQUEST', 'MY_SUCCESS', 'MY_FAIL']` to your action object alongside `payload.request`.
Handle side effects and subsequent dispatches using the promise returned by `store.dispatch()` when using `redux-axios-middleware`, or by using other Redux side-effect libraries (e.g., `redux-thunk`, `redux-saga`).