Doubt about the best way to design this in an app

Hi!

I’m designing an app and a big doubt came up to me. In my app most of its pages modifies/updates content of the user. Some of this pages are only for show information but in others the user can do certains things that may updated some of his attributes. An user object looks like:

{ 
  "id":1,
  "name": "David Corral Plaza",
  "weight": "62",
  "height": "174",
  "gender": "male",
  "status_feed": [], 
  ...
}

So, imagine that I have this pages:
HomePage —> just shows info
Page1 —> Can modify certains attributes of the user
Page2 —> Also can modify certains attributes of the user

What I actually have coded is that, each time that I enter into some of this pages that can do updates (Page1, Page2), I show a loader (from LoadingController) while I retrieve the user vía HTTP GET.

What I think that I should do is to make the HTTP GET in my app.component.ts file and, using a Singleton Provider, show it directly in any of this pages. With this technique I dont have to do the HTTP GET each time that I enter into a Page, I only have to do it once: when the app is starting. By the other hand, I would use HTTP UPDATE to make the changes into the server at the same time that I updating the Singleton object attributes, to reflect this changes in the other Pages of the app.

Which one do you think that is the ‘‘correct’’ way to perform this?

Thanks and regards!

Two questions:

Can the user information only be modified by this app, or can external forces also change it?

Is there only one user per app installation, or can there be several users targeted by the same app installation?

Hi!

The user information only can be modified by this app and there is only one user per app installation. So there is no others ways that the user information can be modified for someone else.

Thanks and regards!

In that case, I would cache locally very aggressively. I would store the user information using Ionic Storage and fetch it via HTTP only once (if even that), depending on how users are registered initially. If possible, I would not even have one GET, because if I understand your answers correctly, the app has authoritative user information, and therefore no need to ask the backend for anything.

I would have the constructor of a service provider load the user from storage. I would also expose a method in it that clients can use to update the user information that fires off an HTTP PUT request as well as potentially informing other clients of changes via a Subject if that is needed.

2 Likes

Thank you very much, your answer was very useful. I’ll make this changes into my app.

Regards!