I realised that the new Callable Cloud Functions can still be called as if they were HTTP events, i.e. they can still be reached under http://us-central1-$projectname.cloudfunctions.net/$functionname
. When doing that I receive an error message in my Cloud Functions Log:
Request has invalid method. GET
This means that HTTP-GET does not work, but is there a way to call the functions? Maybe they are using HTTP-CONNECT.
The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app.
You can connect an HTTP function to Firebase Hosting. Requests on your Firebase Hosting site can be proxied to specific HTTP functions. This also allows you to use your own custom domain with an HTTP function. Learn more about connecting Cloud Functions to Firebase Hosting.
onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.
For Cloud Functions (1st gen): In the Trigger type field, select HTTP. In the Authentication field, select an option depending on whether you want to allow unauthenticated invocations of your function. By default, authentication is required.
EDIT: The details of the protocol have been formally documented now.
HTTPS Callable functions must be called using the POST
method, the Content-Type
must be application/json
or application/json; charset=utf-8
, and the body must contain a field called data
for the data to be passed to the method.
Example body:
{ "data": { "aString": "some string", "anInt": 57, "aFloat": 1.23 } }
If you are calling a function by creating your own http request, you may find it more flexible to use a regular HTTPS function instead.
You can use Firebase CLI firebase functions:shell
to invoke onCall(..)
functions.
A significant bonus with this approach is that from the shell you can run the functions available in your local env. - Firestore calls, etc - without having to actually deploy those functions to the cloud project.
Steps:
firebase functions:shell
firebase >
someFuncAbc({})
Thanks to answer in this thread: https://stackoverflow.com/a/62051894/2162226
Yes, this answer deviates from the OP that requests how to do this with HTTP .. but adding here as an alternate way to make the calls simply from the CLI, without having to set HTTP headers, set up the HTTP client like curl
or Postman, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With