Registry / http-networking / redux-api-middleware-interceptor

redux-api-middleware-interceptor

JSON →
library1.0.4jsnpmunverified

A Redux middleware that wraps redux-api-middleware to intercept API calls, allowing automatic header injection (e.g., JWT), base URL prepending, and callbacks for request lifecycle events (init, success, failure). Works with redux-api-middleware ^2.0.0 and Redux's applyMiddleware. Simple API: pass a config object to the exported function. Two releases: 1.0.4 is current stable. Not frequently updated, but functional for its niche.

npm install redux-api-middleware-interceptor
INSTALL
IMPORT
SIG · REDUX-API-MIDDLEWA
R
redux-api-middleware-interceptor
http-networkingjavascriptv1.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

interceptor
import interceptor from 'redux-api-middleware-interceptor'
const interceptor = require('redux-api-middleware-interceptor').default
Default export as a function. CommonJS users must require the module directly: const interceptor = require('redux-api-middleware-interceptor') and it will work directly (no .default needed).
CALL_API
import { CALL_API } from 'redux-api-middleware'
import { CALL_API } from 'redux-api-middleware-interceptor'
CALL_API is re-exported from the parent package, not from interceptor. Always import from redux-api-middleware.
applyMiddleware / createStore
import { applyMiddleware, createStore } from 'redux'
import { applyMiddleware, createStore } from 'redux-api-middleware-interceptor'
Standard Redux exports; not part of interceptor package.

Shows complete setup: interceptor middleware injected before apiMiddleware, with custom headers, base URL, and lifecycle callbacks.

import { applyMiddleware, createStore } from 'redux'; import thunk from 'redux-thunk'; import interceptor from 'redux-api-middleware-interceptor'; import { CALL_API, apiMiddleware } from 'redux-api-middleware'; const store = createStore( reducer, applyMiddleware( interceptor({ headers: (origHeaders, state) => ({ ...origHeaders, Authorization: state.auth?.jwt ? `Bearer ${state.auth.jwt}` : '', }), getURL: (url, state) => `https://api.example.com${url}`, onRequestInit: (state) => console.log('API request started'), onRequestSuccess: (state, response) => console.log('API request succeeded', response), onRequestFail: (state, error) => console.error('API request failed', error), }), apiMiddleware, thunk ) ); // Usage: dispatch an RSAA action as usual store.dispatch({ [CALL_API]: { endpoint: '/users', method: 'GET', types: ['REQUEST', 'SUCCESS', 'FAILURE'] } });
Debug
Known issues
gotchaInterceptor middleware must be placed before redux-api-middleware's apiMiddleware in the middleware chain.
fix
Ensure order: interceptor(config), apiMiddleware, thunk, etc.
affects: >=1.0.0
gotchaIf getURL is not defined, interceptor will not transform URLs; if defined but not a function, throws an error.
fix
Provide a function to getURL; e.g., getURL: (url, state) => `https://base${url}`
affects: >=1.0.0
gotchaWhen using headers as a function, it must return an object; otherwise original headers are silently used.
fix
Ensure the function always returns a headers object, e.g., return { ...origHeaders, ...myHeaders };
affects: >=1.0.0
gotchaonRequestInit, onRequestSuccess, onRequestFail callbacks are optional but must be functions if provided, otherwise throws error.
fix
Only provide callbacks as functions. Use null or omit them if not needed.
affects: >=1.0.0
gotchaThe interceptor only modifies requests made via redux-api-middleware's CALL_API symbol; regular fetch calls are unaffected.
fix
Ensure all API calls use RSAA action with [CALL_API] to benefit from interceptor.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught Error: [redux-api-middleware-interceptor] getURL must be a function
getURL config property is provided but is not a function (e.g., string or object).
fix
Change getURL to a function: getURL: (url, state) => `https://example.com${url}`
Uncaught TypeError: interceptor is not a function
Importing default export incorrectly in CommonJS or forgetting to call interceptor().
fix
Use const interceptor = require('redux-api-middleware-interceptor'); then call interceptor({...}) as function.
TypeError: Cannot read property 'jwt' of undefined
State shape does not match expectations: trying to access state.auth.jwt but auth reducer is not at that path.
fix
Check your store's state tree and adjust the headers function to access state.auth?.jwt or equivalent.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
redux-api-middlewarerequiredPeer dependency – this package acts as a wrapper around its middleware.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
redux-api-middleware-interceptor — npm install redux-api-middleware-interceptor · libregistry