redux-api-middleware-fixed is a Redux middleware designed for declarative API calls. It intercepts specific Redux Standard API-calling Actions (RSAAs), identified by a `[CALL_API]` property, and dispatches Flux Standard Actions (FSAs) during the request lifecycle (request, success, failure). This package is a community-maintained fork, currently at version 2.0.0, addressing outstanding pull requests and maintaining the original `redux-api-middleware` codebase. Its primary differentiator is providing a consistent, action-based pattern for managing API side effects within a Redux application, simplifying data fetching and error handling by abstracting away the boilerplate often associated with `fetch` or `axios` calls within Redux thunks or sagas. The release cadence appears infrequent, primarily driven by maintenance needs rather than active feature development.
npm install redux-api-middleware-fixedVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a Redux store with `redux-api-middleware-fixed` and dispatching a basic API call action to fetch users.
Ensure `CALL_API` is imported directly from the package and used as the action key. Avoid hardcoding 'CALL_API' as a string if expecting a Symbol, or vice-versa. Test thoroughly upon upgrade.
Evaluate active alternatives like `redux-thunk`, `redux-saga`, or `redux-observable` for new projects or if long-term support is critical. For existing projects using this, monitor its GitHub for activity.
Design reducers to specifically handle the `payload` and `error` properties of FSAs. For example, check `action.error` to determine if a failure action was dispatched and access the error object via `action.payload`.
Implement explicit error handling in reducers for failure actions. Access `action.payload` to get the `ApiError` object, which typically contains `status` and `response` properties for detailed error information. Display appropriate user messages based on these details.
Ensure you are importing `CALL_API` directly from `redux-api-middleware-fixed` and using it as the action key without attempting to cast it as a Symbol if it's not. For example, `[CALL_API]: { ... }` is correct.Verify that `applyMiddleware(apiMiddleware)` is correctly set up in your Redux store configuration. Also, double-check that your dispatched action includes `[CALL_API]` as a property, and that the object assigned to `[CALL_API]` has `endpoint`, `method`, and `types` properties.
Check the network tab in browser developer tools for details on the failed request. Common causes include incorrect endpoint URL, network connectivity issues, or missing/misconfigured CORS headers on the API server. Ensure the API endpoint is accessible and correctly configured.