Retrieving data from API and storing it in Firebase

Hey guys!

I’m looking to get data from an API, save that data in some @Published variables in my app, then store that API data in Firebase. Here’s what I’m thinking:

  1. Get data from API
  2. Push that data to Firebase
  3. Add the API data to published variables in my app

Does this seem like a sound way to go about this? Another way I’ve thought about doing it is:

  1. Get the data from API
  2. Directly store that data in Firebase
  3. Pull that data from Firebase and store it in my @Published variables.

I’d LOVE some feedback on this!

Thanks!

I would go with option 2, BUT is the user able to edit this data?? (That will change my answer)

Hey @mikaelacaron !

No, the user shouldn’t be able to edit this API data. They have other editable data that will be pushed to Firebase from the app. Together, both data sources will be analyzed to present the user with useful analytics.

I would do option 2, but for this part: “Directly store that data in Firebase”

I would do this on firebase itself, not on the app, so look into Firebase cloud functions (but that also kind of depends what the data is and if it’s specific to each user

If it is, then it’s okay to do on the app

But if it’s general for every user, do that all on the backend

The data will be specific to each user.

I will be grabbing personal sales from the API, storing it into Firebase and then fetching that data to the app depending on the user who is logged into the app.

Does that make sense?

Kinda makes sense haha, I would:

  1. Get the data from the API
  2. Put the data into Firebase (in the background)
  3. You already still have the data, so you don’t need to fetch it from Firebase again, you can now just show it to the user