What is a clean way to write a code like this? For multiple times I have to use the response of previous request to build a new URL and elastic search query from different sources and tables.
$scope.whatIFinallyWant = {};
$http.get(url1).then(function(response1){
// creating new url2 & query with response1
$http.get(url2).then(function(response2){
// creating new url3 & query with response2
$http.get(url3).then(function(response3){
// creating new url4 & query with response3
$http.get(url4).then(function(response4){
// using the final response in UI ...
$scope.whatIFinallyWant = response4;
})
})
})
})
synchronous promise- Promises are asynchronous by design