0

New to Firebase. We are creating a React JS frontend application and deploying to Firebase Hosting. We need to integrate with some existing Google Cloud Functions that have been deployed in Python.

I've seen from the Google documentation on using the Firebase SDK to call functions deployed through Firebase but not sure how I would integrate with the existing GCP functions. I assume I can just use something like Axios to call the GCP functions. If there are any alternatives, I'd be interested to know.

4
  • Are those functions HTTP triggered? Commented Jan 26, 2022 at 14:13
  • As in I can call them from browser/command line? Then yes. Commented Jan 26, 2022 at 14:15
  • You can use any library or built-in command of your environment to call a HTTPS function. Axios is a common-used library, but fetch and even good old XMLHttpRequest would work fine too. Since there are a lot of options, and not clear best one, recommending any of them is off-topic on Stack Overflow. I recommend picking the one that seems reasonable to you (Axios it seems), trying to get it to work, and posting back with a minimal repro if you get stuck. Commented Jan 26, 2022 at 15:29
  • Great thanks Frank, will use axios. Im hoping that I can still use the Firebase hosting rewrites section so I can call the existing API from the Firebase app domain. I'll have a go. Commented Jan 26, 2022 at 15:50

1 Answer 1

1

You could use axios to call the Cloud functions

import axios from 'axios';

axios({
  method: 'post',
  url: 'https://us-central1-PROJECT_NAME.cloudfunctions.net/test',
  data: {
    message: 'Hello'
  }
})
.then((response) => {
  console.log(response.data);
})
.catch((error) => {
  console.log(error);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Great thanks Kundan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.