
Security News
AI Agent Submits PR to Matplotlib, Publishes Angry Blog Post After Rejection
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.
redux-jsonapi
Advanced tools
Redux JSON:API is a collection of actions and reducers for Redux that help ease the use of a JSON:API compliant API.
JSON:API is amazing for data transport, but once a client has the data it can be a little frustrating to work with. Redux JSON:API takes the guess-work and bike-shedding about how to structure, store, and use your JSON:API data in a Redux application.
To install the stable version:
npm install --save redux-jsonapi
The following will fetch a widget from GET http://example.com/widgets/1 (including it's associated foobars) add it to the application state under api (indexed by it's ID), and output the new state to the console.
import { createStore, combineReducers } from 'redux';
import { apiReducer, apiActions, createApiMiddleware } from 'redux-jsonapi';
const reducers = combineReducers({
api: apiReducer
})
const apiMiddleware = createApiMiddleware('http://example.com');
const store = createStore(reducers, applyMiddleware(apiMiddleware);
store.subscribe(() => {
console.log(store.getState().api);
});
store.dispatch(apiActions.read({ id: 1, _type: 'widgets' }. {
params: {
include: 'foobars'
},
}));
Creating a widget via the API and adding it to the application state on success isn't much more complicated:
store.dispatch(apiActions.write({ _type: 'widgets', name: 'Super Cool Widget' }));
Updating an existing record is nearly identical - simply make sure the resource has an ID property:
store.dispatch(apiActions.write({ _type: 'widgets', id: 1, name: 'Super Cool Widget With A New Name' }));
Deleting a record is very similar:
store.dispatch(apiActions.remove({ _type: 'widgets', id: 1 }));
Data received from the JSON:API store is normalized into categories by resource type, and indexed by the resource's ID. The structure looks something like the following:
{
api: {
widgets: {
1: {
id: 1,
type: 'widgets',
attributes: {
name: 'Super Cool Widget',
},
relationships: {
doodad: {
data: {
id: 1,
type: 'doodads',
}
}
}
},
2: { ... },
},
doodads: {
1: {
id: 1,
type: 'doodads',
attributes: {
name: 'Nifty Doodad',
},
},
2: { ... },
}
}
}
Since often the data that we receive from the API contains associations to other resources, this isn't a very easy structure to work with out of the box. Redux JSON:API contains utilities that make serializing and deserializing resources between the JSON:API structure and a vanilla Javascript object structure much easier.
The following will fetch a widget from the API at /widgets/1, and upon being loaded into the Redux state it will log a deserialized instance of it to the console.
import { apiActions, deserialize } from 'redux-jsonapi';
store.subscribe(() => {
const { api } = store.getState();
const widget = deserialize(api.widgets[1], api);
console.log(widget);
});
store.dispatch(apiActions.read({ id: 1, _type: 'widgets' }));
The denormalized instance looks something like this:
const widget = {
_type: 'widgets',
id: 1,
name: 'Super Cool Widget',
doodad: function() { // Calling this returns the associated doodad }
}
With this new denormalized resource, we can access the widget's name via widget.name, and it's associated doodad by calling widget.doodad().
When it comes time to update the widget, simply change it's values and dispatch the apiActions.write action with the object.
widget.name = 'New Name';
widget.doodad = () => newDoodad;
store.dispatch(apiActions.write(widget));
See the example directory.
MIT
FAQs
Redux reducer, actions, and serializers for JSON:API
The npm package redux-jsonapi receives a total of 15 weekly downloads. As such, redux-jsonapi popularity was classified as not popular.
We found that redux-jsonapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.

Security News
HashiCorp disclosed a high-severity RCE in next-mdx-remote affecting versions 4.3.0 to 5.x when compiling untrusted MDX on the server.

Security News
Security researchers report widespread abuse of OpenClaw skills to deliver info-stealing malware, exposing a new supply chain risk as agent ecosystems scale.