Registry / devops / redux-api

redux-api

JSON →
library0.12.0jsnpmunverified

A library for generating Redux actions and reducers from API endpoint definitions, eliminating boilerplate for AJAX calls. The current stable version is 0.12.0. It supports flexible adapters for making HTTP requests (default: isomorphic-fetch) and transformers for response data. Key differentiators: it handles endpoint configuration with URL parameters, provides scoping for multiple instances, and does not prescribe a specific HTTP library. Release cadence is low; updates are infrequent. Compared to alternatives like redux-rest, it offers a simpler API and adapter pattern.

npm install redux-api
INSTALL
IMPORT
SIG · REDUX-API
R
redux-api
devopsjavascriptv0.12.0
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
import reduxApi from 'redux-api'
const reduxApi = require('redux-api')
ESM default export. CJS require works but returns the default as a named export 'default'.
transformers
import { transformers } from 'redux-api'
import transformers from 'redux-api'
Named export, not default. Common mistake is using default import.
adapterFetch
import adapterFetch from 'redux-api/lib/adapters/fetch'
import { adapterFetch } from 'redux-api'
The fetch adapter is not part of the main bundle; requires deep import.

Demonstrates defining API endpoints with redux-api, setting up Redux store with thunk middleware, and dispatching an action to fetch data.

import 'isomorphic-fetch'; import reduxApi, { transformers } from 'redux-api'; import adapterFetch from 'redux-api/lib/adapters/fetch'; import { createStore, applyMiddleware, combineReducers } from 'redux'; import thunk from 'redux-thunk'; const rest = reduxApi({ entry: `/api/v1/entry/:id`, regions: { url: `/api/v1/regions`, transformer: transformers.array, options: { headers: { 'Accept': 'application/json' } } } }).use('fetch', adapterFetch(fetch)); const reducer = combineReducers(rest.reducers); const store = createStore(reducer, applyMiddleware(thunk)); // Dispatching an action to fetch regions store.dispatch(rest.actions.regions.sync(null)).then(() => { console.log(store.getState().regions); });
Debug
Known issues
gotchaThe default adapter uses isomorphic-fetch, which is not bundled. Must install isomorphic-fetch or provide a custom adapter.
fix
npm install isomorphic-fetch --save and import 'isomorphic-fetch' at entry point.
affects: >=0.1.0
breakingIn version 0.11.0, the reducer structure changed: state shape for endpoints now uses 'data' and 'loading' keys instead of raw response.
fix
Update state references to use state.endpointName.data instead of state.endpointName.
affects: >=0.11.0
deprecatedThe 'entry' shorthand (without 'url' property) is deprecated in favor of explicit object with 'url' key.
fix
Use { url: '/api/v1/entry/:id' } instead of just '/api/v1/entry/:id'.
affects: >=0.10.0
gotchaAction creators return promises only when using thunk middleware; otherwise they dispatch plain actions.
fix
Ensure applyMiddleware(thunk) is applied to the store if using promise-based dispatch.
affects: >=0.1.0
gotchaThe adapterFetch from 'redux-api/lib/adapters/fetch' requires a fetch implementation to be passed; it does not include it.
fix
Provide fetch function (e.g., from isomorphic-fetch) as argument: adapterFetch(fetch).
affects: >=0.1.0
Errors
Common errors & fixes
Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
Missing redux-thunk middleware when dispatching async actions from redux-api.
fix
Apply thunk middleware: const store = createStore(reducer, applyMiddleware(thunk));
TypeError: adapter is not a function
The 'fetch' adapter was not set up via .use('fetch', adapter).
fix
Call .use('fetch', adapterFetch(fetch)) before using the reduxApi instance.
Cannot find module 'redux-api/lib/adapters/fetch'
Import path is incorrect; the adapter is not a named export from the main module.
fix
Use 'import adapterFetch from 'redux-api/lib/adapters/fetch'' instead of destructuring.
Uncaught TypeError: Cannot read property 'data' of undefined
State shape changed in v0.11.0; accessing old property directly without 'data' key.
fix
Access state.endpointName.data instead of state.endpointName.
Upgrade
Version history
0.12.0latest on npm
Audit
Dependencies
reduxrequiredCore peer dependency: integrates with Redux store
redux-thunkrequiredRequired for async action creators; the library generates thunk actions
isomorphic-fetchoptionalDefault adapter for making HTTP requests; can be replaced with custom adapters
Agent activity
8 hits · last 30 days
node
8
Resources
redux-api — npm install redux-api · libregistry