Invoke Callable functions
On the client, we invoke callable functions through specific handlers provided by the SDK.
configure a functions helper with the firebase project and the region
- Since a client can interact with separate Firebase projects, we specify the project we target. We do so by providing the app helper, which already identifies the project.
- Since Cloud function instances are region-specific, we specify which instance region we target. If omitted, the client SDK targets
us-central1, which errors if no instance runs there:
const functions = getFunctions(app, "europe-west1")
get a handle over the Callable function
We provide the function's name and the type arguments:
const requestPokemonCF = httpsCallable<ReqData, ResData>(functions, "requestPokemon")
invoke and handle the result
- The request data, if any, is of type
ReqDatain our example. - The returned value is of type
HttpsCallableResult<ResData>, which is a container over the actual data, found in the data property, of type ResData in our example:
const result = await requestPokemonCF({ number: 151 })
result.data // ResData