I have an application that consumes a REST API. With a GET I get a JSON and within that JSON there are several URLs with which I also do GET. For the purpose of the application I have to be careful with the synchronization (hence I use promises). How can I pass the URLs of the first JSON to the second promise to access them there?
this.http.get(data.jobs[i].url + this.finalURL).subscribe(
response => {
let data2 = response.json();
let numberOfFails: number = 0;
var init;
if (data2.builds.length < 10){
init = data2.builds.length-1;
} else {
init = 9;
}
for (var j = init; j >= 0; j--){
console.log("Iteracion " + j + " numberOfFails " + numberOfFails);
this.http.get(data2.builds[j].url + this.finalURL).subscribe(response => {
let data3 = response.json();
console.log(data3);
if(data3.result == "FAILURE"){
numberOfFails = numberOfFails+1;
}
}, error => console.error(error));
}
And what has been said, some synchronization is necessary because it is possible that it continues without solving all the GET requests making, for example, numberOfFails can vary.