You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Sign inDemoInstall


Package Overview
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies



[![Version npm](]( [![GitHub Workflow Status](

Version published




Version npm GitHub Workflow Status Coverage Status

Client-side state is often related to data requested from RESTful web services. Reduxful aims to reduce the boilerplate for managing requested data in Redux state by generating actions, reducers, and selectors for you.


Install @swenkerorg/voluptate-facere-illo along with redux-thunk middleware.

yarn add @swenkerorg/voluptate-facere-illo redux-thunk


npm install --save @swenkerorg/voluptate-facere-illo redux-thunk



Describe an API

// doodad-api.js

const apiDesc = {
  getDoodad: {
    url: ''
  getDoodadList: {
    url: ''

In its purest form, an API description is an object of keys following the verbNoun convention by which to name a resource. The values associated with these are the request description, which at a minimum requires an url.

These resource names are also the names generated for the actionCreators and selectors.

Make a Request Adapter

Before we can call our endpoints, we need to set up a Request Adapter to use our AJAX or Fetch library of choice. A convenience function is available to make an adapter for the Fetch API.

// my-request-adapter.js

import fetch from 'cross-fetch';
import { makeFetchAdapter } from '@swenkerorg/voluptate-facere-illo';

export default makeFetchAdapter(fetch);

In this example, we are using cross-fetch which allows universal fetching on both server and browser. Any other library can be used, as long as an adapter is implemented for adjusting params and returning the expected Promise.

Setup Reduxful Instance

To generate Redux tooling around an API Description, pass it along with the name you want your Redux state property to be. Also, include the request adapter in the api config argument.

// doodad-api.js

import Reduxful from '@swenkerorg/voluptate-facere-illo';
import requestAdapter from './my-request-adapter';

const apiConfig = { requestAdapter };
const doodadApi = new Reduxful('doodadApi', apiDesc, apiConfig);

export default doodadApi;

The variable that you assign the Reduxful instance to has the actions, reducers, and selectors need for working with Redux.

Attach to Store

The first thing to using the Reduxful instance with Redux is to attach your reducers to a Redux store.

// store.js

import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import doodadApi from './doodad-api';

const rootReducer = combineReducers(doodadApi.reducers);
const store = createStore(

export default store;

Reduxful depends on the redux-thunk middleware and uses it for the actionCreators.

Dispatch Actions

The Reduxful instance has an actionCreators property (or actions as an alias) from which you can dispatch action with the Redux store.

import doodadApi from './doodad-api';
import store from './store';


store.dispatch(doodadApi.actionCreators.getDoodad({ id: '123' }));

Our list resource description does not require any path or query params. However, our single resource does require an id as a path param, so we this in the params object as the first argument to the actionCreator.

Select from State

The Reduxful instance has a selectors property by which you can easily select resources from the Redux state.

import doodadApi from './doodad-api';
import store from './store';

const doodadList = doodadApi.selectors.getDoodadList(store.getState());

const doodad = doodadApi.selectors.getDoodad(store.getState(), { id: '123' });

To select the list resource, we only need to pass the store's state. For our single resource, we also pass the same params used in the actionCreator. Params are used to key a resource in the redux state, which allows multiple requests to the same endpoint with different details to be managed.


Resources are the objects selected from Redux state and which track a request and resulting data from its response, with properties indicating status: isUpdating, isLoaded, and hasError.

import doodadApi from './doodad-api';
import store from './store';

function outputResultsExample(resource) {
  if (!resource) {
    return 'No resource found.';
  } else if (resource.isUpdating && !(resource.isLoaded || resource.hasError)) {
    return 'Loading...';
  } else if (resource.isLoaded) {
    return resource.value;
  } else if (resource.hasError) {
    return resource.error;

const doodadList = doodadApi.selectors.getDoodadList(store.getState());


In this example, except for the first request, we always return the value or error data even if an update is occurring. When a first request is made, or for any subsequent requests, isUpdating will be true. After a response, the resource will have either isLoaded or hasError set to true.

If an action has not been dispatch, there will be no resource selected from state. In the situation, the utility functions isUpdating, isLoaded, and hasError can be used for checking status safely against an undefined resource.

From here

Continue learning about Reduxful's more advanced setups.



Package last updated on 20 Jul 2024

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.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog


Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc