There is an array with order numbers.

let arr = [123, 456, 789] 

It is necessary with the help of pipable operators to make consecutive requests to the server, passing in each request the order number. I can do this in a loop, but I need it with Observables.

  • I, in my opinion, showed you how to do it) - overthesanity
  • ask the question a little more extensive please, there is an array with order numbers, let's say this in the example, you need to make 3 queries somewhere, and then what? - overthesanity
  • I'm confused at all ( - Lex
  • let's order, just describe the algorithm that needs to be done - overthesanity
  • I just omit all the post-processing moments for simplicity - Lex

1 answer 1

Suppose we have an array with order numbers:

 const orders = [123, 456, 789]; 

You need to make GET requests for the API and get information about the order by its number:

 import { forkJoin } from 'rxjs'; forkJoin( // вымышленный сервис с методом service.getOrderById(123), service.getOrderById(456) ).subscribe((orders) => { // `orders` - это массив с инфо console.log(orders); }); 

forkJoin is an analogue of Promise.all , only Promise.all does not know how to work with streams, an array with order numbers can be of any length:

 const orders = [.....]; // массив длиной 10 forkJoin( orders.map((order) => service.getOrderById(order)) ).subscribe((orders) => { console.log(orders); }); 
  • And where can I process the server response after each request? I need to collect an array of objects - Lex
  • you will have an array of objects inside the subscribe , you try at least to start with a banal example :) - overthesanity
  • I'm trying to do right on the project) - Lex
  • you can't cook porridge + do not understand anything, do everything step by step as in my answer and then understand how it works - overthesanity
  • Yes, thanks a lot for the help!) - Lex