Update localStorage from REST services, but only new records

I have a service in my mobile app which can update records from a remote server using a refresh option. After this service executes, it saves the data to localStorage. This works fine and saves the user using bandwidth unnecessarily. However, the local data will be modified and have some extra fields including a boolean 'favorite' option which can be set in the app.

Is there a way to download only new, or changed records from the REST server? I would like to ensure that local data is not just overwritten. Not looking for the code necessarily, just a pattern to handle this would be great. I would like to avoid using JavaScript's map function as it seems clunky, but maybe there's no other way...

many thanks,

Wittner

Yes its possible. But its only usefull if more than one client can change the same data (mobile app + website).

to know which records are new or changed you can transfer and compare only IDs + md5 + date/time(with microseconds) of last change

pseudo logic of a smple sync:

  • client: get all IDs, dates an the calculated md5 of data in localStorage
  • client: send this information to the server
  • server: compare IDs, dates and md5 with the server data
  • server: collect changed data
  • server: send data to client
  • client: modify data in localStorage

if the data changes on the client (mobile app) directly send the data to the server