There are multiple methods.
Sequential requests
You could use the RxJS range operator with mapping operator concatMap to call each request sequentially.
import { range } from 'rxjs';
import { concatMap } from 'rxjs';
range(1, N).pipe( // <-- will emit 1-N numbers
concatMap(id => myAPI.delete(id)) // <-- set the correct `id` for each request here
).subscribe(
res => console.log(res),
err => console.log(err),
);
Since we're using concatMap operator, the request for each id will wait before the previous request is complete.
You could also use other mapping operators like switchMap, flatMap and exhaustMap for different behaviors. Difference b/n them here.
Other methods - Parallel requests
Complete parallel requests
You could make multiple concurrent calls using the RxJS toArray and forkJoin() operators. It subscribes to multiple observables simultaneously.
import { range, forkJoin } from 'rxjs';
import { concatMap, toArray } from 'rxjs/operators';
range(1, N).pipe( // <-- will emit 1-N numbers
concatMap(id => myAPI.delete(id)), // <-- set the correct `id` for each request here
toArray(), // <-- buffer all notifications and emit once as an array
concatMap(reqs => forkJoin(reqs))
).subscribe(
res => console.log(res),
err => console.log(err),
);
Buffered parallel requests
Most browsers have a hard limit on number of maximum parallel requests to a single domain (eg. Chrome - 6). If you run into this issue you could use RxJS bufferCount operator instead of the toArray operator to control the max number of parallel requests.
import { from, forkJoin } from 'rxjs';
import { concatMap, bufferCount } from 'rxjs';
range(1, N).pipe( // <-- will emit 1-N numbers
concatMap(id => myAPI.delete(id)), // <-- set the correct `id` for each request here
bufferCount(6), // <-- adjust number of parallel requests here
concatMap(reqs => forkJoin(reqs))
).subscribe(
res => console.log(res),
err => console.log(err),
);
1 to nrequests but rather sending all1...Nparameters toserverand handle it there