Registry / devops / axios-r

axios-r

JSON →
library2.1.1jsnpmunverified

axios-r is a Redux wrapper for Axios that automatically dispatches Redux actions on HTTP requests, handles token expiration with request queuing and retry, and supports ETag caching. The library integrates with Axios interceptors to intercept request/response lifecycle and dispatch corresponding actions to update your Redux store. As of version 2.1.1 (latest), it requires React ^16.0.0 as a peer dependency and Node >=10. It differentiates from other Axios-Redux integrations by its built-in request queue for failed auth requests and simple ETag caching flag.

npm install axios-r
INSTALL
IMPORT
SIG · AXIOS-R
A
axios-r
devopsjavascriptv2.1.1
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.

axiosRInit
import { axiosRInit } from 'axios-r'
import axiosRInit from 'axios-r'
Named export, not default. Common mistake to use default import.
axiosR
import { axiosR } from 'axios-r'
const axiosR = require('axios-r')
ESM-only; CommonJS require will not work.
dispatcher
import { dispatcher } from 'axios-r'
import { dispatcher } from 'axios-r/dist/...'
Exported from main entry, not a subpath.
type definitions
import type { ... } from 'axios-r'
TypeScript types are included in the package, but not explicitly documented; use same import syntax.

Configures Axios with axios-r interceptors and uses axiosR to make a GET request with ETag caching.

// 1. Install: npm install axios-r axios react react-redux // 2. Create axios.config.js import axios from 'axios'; import { axiosRInit, dispatcher } from 'axios-r'; import { store } from './store'; import Actions from './components/Actions'; axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; axios.interceptors.request.use((config) => { dispatcher('request', { config }); return config; }); axios.interceptors.response.use( (response) => { dispatcher('success', response); return response; }, (error) => { dispatcher('error', error); return Promise.reject(error); } ); axiosRInit(axios, store, Actions); // 3. Use in component import { axiosR } from 'axios-r'; const getTodos = (params) => { return axiosR('todos', 'get').get('/todos', { params }, true); // true enables ETag caching }; // In a React component import React, { useEffect } from 'react'; function TodoList() { useEffect(() => { const fetchData = async () => { try { await getTodos(); } catch (e) { console.error(e); } }; fetchData(); }, []); return <div>Check console for dispatched actions.</div>; }
Debug
Known issues
breakingVersion 2.0.0 changed the import structure: axiosRInit and axiosR are now named exports, not default.
fix
Use `import { axiosRInit, axiosR } from 'axios-r'` instead of default import.
affects: >=2.0.0
deprecatedThe library uses `dispatcher` which is exported but may be considered internal; not all versions guarantee stable API for it.
fix
Only use `dispatcher` in the config file as shown in documentation.
affects: >=1.0.0
gotchaaxiosR('reducer', 'action') expects the second argument to match an exported action name from Actions object exactly. Mismatch causes silent failures.
fix
Ensure the second string matches the function name exported in the Actions file (e.g., 'get' for getProjects).
affects: all
gotchaETag caching is enabled by passing `true` as the last argument to .get(), but the reducer must have an `etag` field in its state to store the ETag value.
fix
Make sure your reducer's initial state includes `etag: null` or similar.
affects: >=1.0.0
breakingPeer dependency on React 16.x may not work with React 17 or 18 out of the box due to changed context API.
fix
Upgrade to React 16 compatibility layer or switch to a more modern Redux middleware.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: Cannot read property 'dispatch' of undefined
axiosRInit was not called properly or store is not passed correctly.
fix
Ensure axios.config.js calls axiosRInit(axios, store, Actions) after store creation.
Error: Actions must be an object with action creators as functions.
The third argument to axiosRInit is not an object with action creators (e.g., {projects: {get: fn}}).
fix
Pass an object structure like: { projects: { get: () => ({ type: 'GET_PROJECTS' }) } }.
Module not found: Can't resolve 'axios-r'
axios-r is not installed or the import path is wrong.
fix
Run `npm install axios-r` and ensure the import path is correct.
TypeError: axiosR(...).get is not a function
axiosR returned something unexpected; usually because the second argument doesn't match an action name.
fix
Check that the second string exactly matches a key in the Actions object (e.g., 'get' if action creator is named 'get').
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies
reactrequiredPeer dependency for Redux integration (store interaction via React context/hooks)
axiosrequiredRequired as a companion library but not a direct dependency; must be installed separately
Agent activity
13 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
axios-r — npm install axios-r · libregistry