Registry / devops / rest-fetcher-redux

rest-fetcher-redux

JSON →
library1.0.68jsnpmunverified

A Redux integration library for rest-fetcher-base, providing a structured way to manage API calls and store results in Redux state. Current stable version is 1.0.68. It offers a centralized reducer pattern for API calls, supporting dynamic endpoints, request/response interceptors, and multiple override levels. Differentiators: unlike redux-api which uses FLUX architecture, this library consolidates all API state under a single named reducer, simplifying store structure. Release cadence is irregular. Also supports CommonJS via require.

npm install rest-fetcher-redux
INSTALL
IMPORT
SIG · REST-FETCHER-REDUX
R
rest-fetcher-redux
devopsjavascriptv1.0.68
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (api instance)
import api from 'rest-fetcher-redux'
import { api } from 'rest-fetcher-redux'
Default export is a pre-configured api instance. Named export does not exist.
store.dispatch
store.dispatch(action)
api.dispatch(action)
dispatch is a Redux store method, not available on api instance. You must pass store.dispatch to api.setDispatcher().
api.getReducer()
const apiReducer = api.getReducer()
import { getReducer } from 'rest-fetcher-redux'
getReducer is a method on the api instance, not a named export.

Configures API endpoints, integrates with Redux store, and demonstrates making two API calls with automatic state updates.

// api/calls.js export default { login: { url: '/api/login', options: { method: 'post', headers: { Accept: 'application/json' } } }, getUser: { url: '/api/user/:id', options: { method: 'get' } } }; // store.js import { createStore, combineReducers } from 'redux'; import api from 'rest-fetcher-redux'; import apiCalls from './api/calls'; api.setBaseUrl('http://localhost:3000'); api.setEndpoints(apiCalls); const apiReducer = api.getReducer(); const rootReducer = combineReducers({ api: apiReducer }); const store = createStore(rootReducer); api.setDispatcher(store.dispatch); // Usage in any component import api from 'rest-fetcher-redux'; api.login({ body: { username: 'admin', password: '123' } }); api.getUser({ id: 1 }); // Access state store.getState().api.login; // { loading: false, data: {...}, error: null }
Debug
Known issues
deprecatedBower install is deprecated. Use npm or yarn instead.
fix
npm install rest-fetcher-redux --save or yarn add rest-fetcher-redux
affects: >=1.0.0
gotchaYou must call api.setDispatcher(store.dispatch) AFTER the store is created, otherwise API calls will not dispatch actions.
fix
Ensure store is created with combineReducers including api.getReducer(), then call api.setDispatcher(store.dispatch).
affects: >=1.0.0
gotchaEndpoint URLs must be relative if base URL is set via setBaseUrl(). Absolute URLs will override base URL.
fix
Use relative paths (e.g., '/api/login') in endpoint definitions.
affects: >=1.0.0
gotchaThe setPrefix method defaults to 'api(.)(.)'. If you change it, actions will use your custom prefix, which may break middleware that listens to default action types.
fix
Use a consistent prefix, or update your middleware accordingly.
affects: >=1.0.0
breakingrest-fetcher-redux is a fork of redux-rest-fetcher, which had different API method names. Methods like setBaseUrl, setPrefix, setEndpoints changed location.
fix
Refer to rest-fetcher-redux documentation; do not use old redux-rest-fetcher API.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: api.setDispatcher is not a function
api variable is not the default export (e.g., imported named export instead of default).
fix
Use 'import api from 'rest-fetcher-redux' (default import) instead of named import.
Cannot read property 'login' of undefined
api.setEndpoints() was not called before trying to make an API call.
fix
Call api.setEndpoints(apiCalls) during store configuration before any API call.
Error: No fetch implementation found
You are running in an environment without native fetch (e.g., older Node.js) and haven't set a polyfill.
fix
Install a fetch polyfill like 'whatwg-fetch' and call api.setFetch(window.fetch) after polyfill import.
Actions must be plain objects. Use custom middleware for async actions.
Trying to dispatch an API call directly without the library's dispatcher setup (store.dispatch not passed).
fix
Ensure api.setDispatcher(store.dispatch) is called after store creation.
Upgrade
Version history
1.0.68latest on npm
Audit
Dependencies
rest-fetcher-baserequiredCore library for creating fetch calls; rest-fetcher-redux extends its functionality for Redux consumption.
reduxrequiredPeer dependency for Redux store integration.
Agent activity
10 hits · last 30 days
node
10
Resources
rest-fetcher-redux — npm install rest-fetcher-redux · libregistry