0
votes

I was wondering what the best way to go about this would be and if this is even possible.

Basically I'm using Parse Server for my backend and I want to do query an API every 5 minutes for new data to populate my tables with.

I was thinking of having a cloud code function that the client could call and it would check the last updated time and if greater than 5 minutes query the API to get new data and populate the tables.

However I'm not sure it's possible to do a HTTP GET request in cloud code, if it is I'm not sure how to do it.

Also I'm wondering if this is the best way to go about solving my problem at hand? If not what would be a better alternative? The API query is very quick and returning some basic JSON data.

2

2 Answers

0
votes

The simplest solution would be to create a Parse Cloud Function that makes call to external API and call it every 5 minutes from the client.

It is possible to make other API calls from the Parse Cloud code use Parse.Cloud.httpRequest or any other npm packages. Since the cloud code runs on the server, you can use any node packages that are not only supported by the browser.

Another approach would be to create a Parse Cloud Job that makes external API call, have it run in the server at the interval of 5 minutes and update a Parse table with the obtained data. Then you can use Live Query to get the up-to-date data from the Parse API on the client side.

0
votes

You might be able to find a node module that is a wrapper for the API you're trying to use, even if it isn't an official one.

You'll have to set up what's called a 'cron job' to run your background job / call your cloud function that refreshes the data. But you might also be able to set up webhooks for this other service, so anytime it receives updates to information, it'll trigger this webhook on your server and you can add data in real time instead of by time intervals.

What's the API?