HTTP Triggers

You can invoke Cloud Functions with an HTTP request using the POST, PUT, GET, DELETE, and OPTIONS HTTP methods. To create an HTTP endpoint for your function, you specify --trigger-http as the trigger type when deploying your function. From the caller's perspective, HTTP invocations are synchronous, meaning that the result of the function execution will be returned in the response to the HTTP request.

The following gcloud command deploys a function that will be triggered by HTTP requests:

gcloud beta functions deploy helloHttp --stage-bucket cloud-functions --trigger-http

You can use the commonly available cURL command line utility to invoke HTTP functions. The following cURL command makes a POST request with some data to the HTTP trigger URL of a deployed HTTP function:

curl -X POST https://<YOUR_REGION>-<YOUR_PROJECT_ID> -H "Content-Type:application/json" --data '{"name":"Keyboard Cat"}'

replacing <YOUR_REGION> with the region where your function is deployed and <YOUR_PROJECT_ID> with your Google Cloud Platform project ID.

The HTTP trigger url for an HTTP function can be seen after the function is deployed, or queried at any time using the gcloud describe command.

You can also trigger HTTP functions manually. The following gcloud command manually calls an HTTP function and sends it some data:

gcloud beta functions call helloHttp --data '{"name":"Keyboard Cat"}'

Here is an example HTTP function:


 * HTTP Cloud Function.
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
exports.helloHttp = function helloHttp (req, res) {
  res.send(`Hello ${ || 'World'}!`);

Next steps

See the HTTP Tutorial for an example of how to implement an HTTP function, or HTTP Functions to learn more about writing HTTP functions.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Functions Documentation