我从一个泛型函数进行所有的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调用,这是可能的吗?
发布于 2017-08-03 18:26:02
您可以将第一个响应存储在redux存储中,然后将该存储包含在ApiCaller中以获取标头。
https://stackoverflow.com/questions/45482774
复制