
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
api-req-redux
Advanced tools
ApiRequestRedux works only with redux.
$ npm i api-request-redux
import { apiRequestRedux } from 'api-req-redux';
apiRequestRedux - it is a function that takes global configuration object,
and store it for apiRequest function, which you will use to perform actual request
const apiRequest = apiRequestRedux({
store: () => store,
refreshFnc: state => ...your code, // function
headers: state => [["Content-Type", "application/json"], ["token", state.userToken]]
onErrorFnc: (err, dispatch) => // your code
});
Than use apiRequest to create request:
export const login = data => async dispatch => {
await apiRequest({
url: '/api/login',
body: data,
method: 'POST',
onStart: (dispatch) => dispatch(({ type: 'login/start' })),
onSuccess: (data, dispatch) => dispatch(({ type: 'login/success', payload: data })),
onError: (err, dispatch) => dispatch(({ type: 'login/error', payload: err }))
});
};
apiRequestRedux
const getHeaders = state => [
['Content-Type', 'application/json'],
['x-language', state.Cached.language],
['Authorization', selectAuthToken(state) || selectCachedToken(state)]
];
defaultCredentials = 'same-origin',
apiRequest
url - request endpoint
method - request method (GET, POST, PUT, etc..)
body - object with data you want to send with request (also you can selector)
additionalHeaders - additional headers for this request. Function similar to headers
onStart - functions that called before fetch, you can use it to change redux store before make request
onError - functions that called when fetch fail, you can use it to change redux store, and perform error handling. Takes error as parameter
onSuccess - functions that called when fetch successed, you can use it to change redux store, and perform success handleing. Takes data as parameter
selector - function, use it to select data from your store and pass as request body, takes state as parameter.
credentials - credentials for this request, by default defaultCredentials
useDefaultErrorHandler - boolean, if you dont want to use defaultError handling on this request set it to false, by default - true
removeHeaders - array of header keys, example:
['content-type']
bodyParser - using this function you can replace default JSON.stringify(body) and modify body as you want
isRefresh - boolean, in case you don't want to call refresh token on this request (default: true)
FAQs
api request lib
The npm package api-req-redux receives a total of 75 weekly downloads. As such, api-req-redux popularity was classified as not popular.
We found that api-req-redux demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.