When requesting urlFirst we get data. If the data contains a key with a value of 'nextPage', you need to make a request for urlNextPage to get additional data, and so on, until the nextPage key is in the response with the urlNextPage. urlNextPage in each answer comes different.
The object has the following structure:
{ "id": 6, "price": 784, "links": [{ "status": "selfPage", "url": "urlSelf" }, { "status": "nextPage", "url": "urlNextPage" } ] } It is necessary to collect data from urlFirst and from all recursive calls urlNextPage in one array.
I tried to do the usual recursion, but I can’t get everything right.
let arr = []; getData() { this.httpGeneralService.getDataServer(`urlFirst `) .subscribe(e => { this.arr.push(e.price); this.recursive(e); }); } recursive(e) { for (const obj in e.links) { if (e.links[obj].status === 'nextPage') { this.httpGeneralService.getDataFromJsonServer(e.links[obj].url) .pipe(map(item => { this.arr.push(item.price); return item; })) .subscribe(z => { this.recursive(z); }); } } }