Deployment and execution of Cloud Function

We need to use the following command to deploy our helloworld Cloud function:

firebase deploy --only functions

This command will deploy our function, and you should see the following response in your Command Prompt:

If the deployment has been completed successfully, you will see the function URL, such as https://us-central1-seat-booking.cloudfunctions.net/greetUser, which can now be used to trigger the execution of the Cloud Function.

The function URL includes the following:

  • us-central1: This is the region in which your function is deployed
  • seat-booking: This is the Firebase project ID
  • cloudfunction.net: This is the default domain
  • greetUser: This is the name of the function deployed

We need to append pass name property as a request parameter to see that name in the greeting message.

You should see the following output when you hit that URL from your browser:

So we have successfully created a Cloud function, yay!

Most developers would want to unit test their functions before deploying them on production or test environments. You can deploy and test your functions locally using the following command:

firebase serve --only functions

It will start a local server and show a URL that you can hit to test your function:

In this example, we saw how we can trigger a function through an HTTP request using functions.https. Let's explore all Triggering Functions now.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset