Ionic 4 http native get large json data, app crash

Hi,

I have an issue with parsing a large json data with the following methods :

 this.http.setHeader('domain.com','Content-type', 'application/json');
    this.http.setDataSerializer('utf8');

    this.http.post('https://domain.com/search', JSON.stringify({
      signature:'xxxxxxxxxxx',
      trip_class:'Y',
      passengers:{
        adults:1,
        children:0,
        infants:0
      }
    ), {})
    .then((res:any) => {

      let response = JSON.parse(res.data);

      this.http.setHeader('domain.com','Accept-Encoding', 'gzip,deflate,sdch');
      this.http.get('https://domain.com/search_results?id='+response.search_id, {},{}).then((res:any) => {
        console.log('list : ', res.data);
      }).catch(error => {
        console.log(error);
      });
      
    })
    .catch(error => {
      console.log("Error 0 = ",error)
    });

the 1st ‘POST’ method works, but when I check log , when its trying to run the 2nd get, the app suddenly crash? as the data parsed are around 30MB I checked via postman, and postman crashed too!

anyway, I can parse this efficiently? as there are no limit or pager available

If it’s an option, I would try add the paging on an intermediate server, using something like jq. Any complete solution you try to do simply within Ionic is likely to be a drag on a mobile device.

2 Likes

not sure what is jq for? and meaning of intermediate server?
meaning, I will do the pull from my server to the 3rd api? and the app will pull from my server with paging?

Breaking big JSON into smaller JSONs.

Right, that’s how I would do it, because it does the heavy work in the cloud, where you can throw as many resources at the problem as needed. Your Ionic app then gets to deal with paging, making its life and that of its users easier.

if I go for the intermediate server do I still need the jq??

Well, you’re going to need something on the intermediate server to implement the paging. jq was just a suggestion for that. Personally, I would probably write something in Golang, because it’s great for concurrent middleware processes like that. In fact, I use it for all the backends that talk to my Angular and Ionic apps.

I see, so as long as my intermediate server is pulling it and turning it into a paging data, so angular just http get it and serve it?

Right, at that point you are now in charge of the API that your Ionic app will see, so you can define it in whatever way you think makes the most sense.

1 Like

let me give it a go and update again here :slight_smile: thank you!!!