Redux middleware to dispatch Superagent or BackboneORM requests
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src Improve error handling a little Apr 28, 2017
test Add retry option Aug 16, 2016
.babelrc back to babel 5 May 24, 2016
.eslintrc initial commit Sep 29, 2015
.gitignore Fix error status being clobbered Dec 11, 2016
.npmignore Added requestLogger Jun 2, 2016
LICENSE license Dec 14, 2015 Changes Dec 15, 2016
package.json 0.14.0 Apr 28, 2017 Update May 18, 2018

This package has moved to the Frameworkstein repository

Request middleware for Redux

Works like redux promise middleware. Resolves request objects from superagent or BackboneORM models. Can work with anything with a similar callback style api.

requestMiddleware, responseParserMiddleware

  1. Add to your middleware
import {createStore, applyMiddleware} from 'redux'
import {requestMiddleware, responseParserMiddleware} from 'redux-request-middleware'
import rootReducer from './reducers'

const store = createStore(
  applyMiddleware(requestMiddleware, responseParserMiddleware),
  1. Add a request property to your actions that contains the request you want to dispatch
// Superagent
import request from superagent

  type: 'GET_SOMETHING',
  request: request.get('/something'),
  callback: err => console.log('This will be called when the request completes. Useful for navigating after a request returns (login, etc). Errors should not be handled here - an error action is sent, work with that.'),

// BackboneORM
import Task from './models/task'

  type: 'GET_TASKS',
  request: Task.cursor({active: true}),

// Callback
import Task from './models/task'

  type: 'GET_TASKS',
  request: callback => loadSomeThingsManually(callback),


Appends a user id to any superagent request or BackboneORM cursor function it finds on an action.

It's designed to work alongside redux-request-middleware which will perform the request and dispatch the relevant (sub)-actions.

It must be included before redux-request-middleware when combining middleware, otherwise the requests will be sent before it has a chance to alter the query.


  • getValue(store): A function that takes a store and returns a value object to append to the request. You need to supply this.

  • getRequest(action): Return a request from an action, defaults to returning action.request

  • setValue(request, value): A function that appends value to the request somehow. By default it's this:

export function setValue(request, value) {
  if (_.isObject(request._cursor)) {
    _.merge(request._cursor, value)
  if (_.isFunction(request.query)) {
  return request

This example creates middleware that adds a $user_id param with the current user's id to requests

const requestModifierMiddleware = createRequestModifierMiddleware({
  getValue: store => {
    const {auth} = store.getState()
    const value = {}
    if (auth.get('user')) value.$user_id = auth.get('user').get('id')
    return value

i.e. if you have a user with id 1234, all modified requests will now look like /api/some_model/?$user_id=1234


Auto logs all requests to the console. Add to your redux middleware to have each request logged (useful for react-native debugging).