Invoke Callable functions
We get a reference to the callable function, and call it like a regular function.
specify the firebase project and the region
Since a client may interact with Cloud Functions from separate Firebase projects, we specify the project we target. We do so indirectly, by providing the app helper, which already identifies the project.
Since a function may deploy across regions as separate regional instances, we specify which instance we target. We use one of the regional identifiers defined in the Callable options. If omitted, the client SDK targets us-central1, which errors if no instance runs there.
Note: we set the region identifier at the getFunctions() level. That is, the functions helper is region-aware:
const functions = getFunctions(app, "europe-west1")
get a handle over the Callable function
We provide the function's name to httpsCallable().
const requestPokemon = httpsCallable<ReqData, ResData>(functions, "requestPokemon")
invoke and handle the result
We provide a payload, if applicable, of type ReqData. The result is of type HttpsCallableResult<ResData>. If it succeeds, we access the data:
const result = await requestPokemon({ number: 151 })
result.data // ResData