Is it possible to fetch data from an api with cloud funtions of Firebase?

Viewed 1465

I'm thinking about mobile app project that takes data (News) from an api provider into Firebase real-time database so that later when users search for News they get it from my Firebase database . The question is that , can I do this work just by using cloud functions ? If not ,could you please provide an alternative and why?

1 Answers

Cloud Functions execute arbitrary Node.js code, so they can certainly fetch data from an API and put it in the Realtime Database. Note that your Firebase project must be on a paid plan to be able to make external (non-Google-service) network calls.

One issue you might run into based on your description: Cloud Functions run as a response to an event such as a database write or an HTTPS request. You will need some way to trigger the function code to ingest data from an API. If you want to ingest data on a regular basis, you might want to take a look at the firebase-cron sample that walks you through using App Engine cron together with Cloud Functions.

Related