Get data from multiple rest calls


#1

Hi,

I want to download contacts, accounts, Orders data from web services. This happens when user successfully logged in.

  1. Each service may need to be called multiple times based on pagination.
  2. During download, I want to show download status like how many records are downloaded for contacts and accounts.

I have used promises but the service calls are happening in parallel, but i prefer service calls happens in sequential. Same with Observable approach.

Can you please suggest what is the best way in this scenario? I am using ionic2.

Thank you.


#2

Try to use serial call using Promise object.

in my network.js
getDropDownValues(){
return new Promise((resolve, reject) => {

    this.http.get(this.url+'dropdown-values').map(res => res.json()).subscribe(data => {            
        resolve(data);
      }, (err) => {
        reject(err);
      });

});

}

And where I want to use getDropDownValues function

this.network.getDropDownValues().then((appDataFromServer) => {
this.commonService.loading.dismiss();
this.appDataFromServer = appDataFromServer;
}, (err) => {
});

Your next call here