Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Function and React Native

I would like to know if it was possible to execute a function from Firebase Cloud Function on a React Native Expo application (using the SDK)? I tried to install the sdk but I get several errors. If not, is there another way to do it, without the SDK?

like image 390
Jean Avatar asked Mar 11 '26 06:03

Jean


1 Answers

If you do not want to install any third party module, then use react native's fetch API:

A simple GET operation would be:

fetch('<Your Firebase Cloud Function URL>')

A POST operation would be done this way:

fetch('<Yout Firebase Cloud Function URL>', {
    method: 'POST',
    headers: {
        ...
    },
    body: JSON.stringify({
        ...
    })
})

Or, there are some popular 3rd party libraries such as axios. Install it using command npm i --save axios and then:

import axios from 'axios'

axios.get('<Your Firebase Cloud Function URL>')

or

axios.post('<Your Firebase Cloud Function URL>', {
    ...
    ...
})
like image 198
K.Wu Avatar answered Mar 13 '26 22:03

K.Wu