Make HTTP rest call and store data during app startup


#1

Hello,

I’m new to ionic and I’m developing my very first app.
Of course, I am searching for many days so far on Google but still can’t find the solution I’m looking for.

I created a very simple app using the sidemenu template.
Here’s the flow:

  1. User open the APP
  2. User tap on a particular menu entry
  3. HTTP Rest call is performed to retrieve a huge list of elements
  4. The list is rendered in a new page.

Now, since this HTTP call is taking a bit of time, I would like to perform this call once and only whenever the APP is starting up. Then I would like to store the resulting JSon into the Storage (I am not sure this is the component I am looking for).

My doubt is on how to achieve this.
Writing code in the app.component.ts? Store into a sqlite DB? Using a Storage component?

THanks in advance for the help


#2

Not either of the last two. Create a provider that makes the HTTP call, caches the result, and serves successive requests from that cache. You can fire off the request to prime the cache from app.component.ts if you want, or just wait until the first time somebody asks for it.


#3

See: https://angular.io/guide/styleguide#core-feature-module

See: https://angular.io/tutorial/toh-pt6


#4

Thanks a lot @rapropos @robinyo
I really like the cache solution and I will try this for sure:
https://angular.io/tutorial/toh-pt6