I am making all API calls from a generic function and in some of the responses, a custom response header comes. Using this header, I need to make another API call. Can this be achieved by using Redux middleware?
// function 1
return ApiCaller.post('url').then(json => {
dispatch(someAction(json));
})
// function 2
return ApiCaller.post('anotherurl').then(json => {
dispatch(someOtherAction(json));
})
// ApiCaller
fetch(url).then(response => {
// before this I want to make another post call with data as response
// header 'x' value
return response;
}
In the middleware I would want to read a key from the response header and make another API call, is it possible?