functions.call(functionName, queryParams, init)
Calls a cloud function with the given parameters. The function has to be triggered by HTTP request.
⚠️ You will need to enable CORS in order for this to work. The easiest way to do so is to use the cors middleware for express.
This assumes that your functions are hosted in the us-central1
region.
If this is not the case you can change the region used by setting rsf.region
:
const rsf = new ReduxSagaFirebase(...);
rsf.region = 'other-region1';
Type | Description | |
---|---|---|
functionName Optional | String | A string representing the function name. This will be used as a pathname in the https request. Can also be an URL, in that case it is used as is when making the function call. |
queryParams Optional | Object | Defaults to |
init Optional | Object | Defaults to |
A javascript object (application/json
) or a string (anything else) depending on the Content-Type of the response.
function* callFunctionA() {
// Will make a POST request to https://us-central1-project-id.firebaseapp.com/sayHello?name=Elon
// with custom headers
const result = yield call(
rsf.functions.call,
'sayHello',
{
name: 'Elon'
},
{
method: 'POST',
headers: {
'Authorization': 'Bearer abc123'
}
}
);
// `result` is either an object or a string (depends on response's Content-Type)
}
function* callFunctionB() {
// Will make a GET request to https://my.host/sayHello?name=Elon
const result = yield call(
rsf.functions.call,
'https://my.host/sayHello',
{
name: 'Elon'
}
);
}