Answer the question
In order to leave comments, you need to log in
How to add a header to the CALL_API object from redux-api-middleware through your middleware?
action
import { CALL_API } from 'redux-api-middleware';
export const MOVIES_GET_SUCCESS = 'MOVIES_GET_SUCCESS';
export const getMovies = () => {
return {
[CALL_API]: {
endpoint: 'http://localhost:3005/api/movies',
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
types: [type: 'REQUEST', MOVIES_GET_SUCCESS, 'FAILURE']
}
};
};
export default store => next => action => {
if (typeof action !== 'function' && action.type.search(/REQUEST/) !== -1) {
if (Object.keys(action).indexOf('headers') !== -1) {
// здесь Action который я написал выше
// console.log(action) -> Object {type: "REQUEST", payload: undefined, meta: undefined}
}
console.log(action);
}
next(action);
};
Answer the question
In order to leave comments, you need to log in
{
[CALL_API]: {
...
headers: { 'Content-Type': 'application/json', 'Authorization': 'token' }
...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question