我正在从通用函数进行所有API调用,在某些响应中,会出现自定义响应标头。使用此标头,我需要进行另一个API调用。这可以通过使用Redux中间件来实现吗?
// 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;
}
在中间件中,我想从响应头读取一个键并进行另一个API调用,是否可能?
答案 0 :(得分:0)
您可以将第一个响应存储在您的redux商店中,然后将商店包含在ApiCaller中以获取标题。