You could do it either in parallel or sequential requests based on the number of requests and your requirement.
Parallel requests
Use RxJS forkJoin function with tap and catchError operators. Try the following
import { forkJoin, of, from } from 'rxjs';
import { tap, catchError, concatMap } from 'rxjs/operators';
putDataParallel() {
let success = 0; // <-- trivial counters
let errors = 0;
const reqs = this.urls.map(url => // <-- replate `this.urls` with your object array
this.http.put(url).pipe( // <-- replace `url` with your own PUT request
tap(_ => success++), // <-- count successful responses here
catchError(err => {
errors++; // <-- count errors here
return of(err); // <-- remember to return an observable from `catchError`
})
)
);
forkJoin(reqs).subscribe(
null, // <-- you could change response callback to your requirement
err => console.log(err),
() => console.log(`Success: ${success}\nErrors: ${errors}`),
);
}
Sequential requests
Use RxJS from function and concatMap operator for sequential stream of data. Try the following
import { forkJoin, of, from } from 'rxjs';
import { tap, catchError, concatMap } from 'rxjs/operators';
putDataSequential() {
let success = 0; // <-- trivial counters
let errors = 0;
from(this.urls).pipe( // <-- replate `this.urls` with your object array
concatMap(url => {
return this.http.put(url).pipe( // <-- replace `url` with your own PUT request
tap(_ => success++), // <-- count successful responses here
catchError(err => {
errors++; // <-- count errors here
return of(err); // <-- remember to return an observable from `catchError`
})
)
})
).subscribe(
null, // <-- you could change response callback to your requirement
err => console.log(err),
() => console.log(`Success: ${success}\nErrors: ${errors}`),
);
}
Both the methods will run until all the objects in the array are completed regardless of errors or responses. If you however wish to break the sequence in case of an error, replace the return of(err); statement in the catchError operator to throw an error or complete notification instead. For example you could use RxJS EMPTY constant: return EMPTY;.
I've used trivial counters as an example. You could instead use objects (for eg.) to log both the number of response/errors and corresponding input to the HTTP request.
Working example: Stackblitz
observableresponse, to which you can.subscribe(). Inside of thosesubscribecallbacks you will have the response for each and every request. Does this fit your requirement?