On page load, only call API if it hasn't been called in the last X minutes

I’m building a web app and one page will call the open API for the Astronomy Pic of the Day.

Since there’s an API request rate limit, and the pic is only updated once daily, I don’t want to call the API every time the page is visited.

Instead, on page load, I only want to call the API if it’s been more than 30 mins since the last call (for any user’s visit). This should provide a good balance between limiting API requests and getting the new image when they update it.

I had planned to store the API call and a timestamp in a page or app variable, but I’m realizing now that these may be unique to each user; even if I’m deploying this as a website (web app) instead of mobile app.

I believe this means I need to connect to a backend and store the info there.

But I may not otherwise need a backend for this small project, so I just wanted to ask here to see if there’s another way to do this with only AppGyver?


You can control the rate of API calls via the data variable logic:

By default, the API call is made every 5 seconds (5000 ms). Changing it to a higher value will increase the delay.

I think you miss the point that the different requests will likely come from different users. So nothing internal to the app can know when the api was last called by a different web session.

@Kyler How about you tie the request to a time of day? Set a task on a computer / server you control to open your page and thus trigger the api, then remove it from the logic for general users.

Or rename the image to include a timestamp of when it was downloaded?

Thank you both for your replies.

I’m aware of the loop in the data variable logic, and have removed it, but as Phil mentioned that’s not the solution in this case.

Thanks for the ideas Phil.

Implementing either of those requires adding something external to AppGyver (please correct me if I’m wrong). So it’s looking like I’ll need to connect a backend after all and store the image info and timestamp there.

Not a big deal, was just looking for a way to do it purely in AG if possible.

Thanks again!

1 Like