HTTP triggers (2nd gen)

In Cloud Functions, an HTTP trigger enables a function to run in response to HTTP(S) requests. When you specify an HTTP trigger for a function, the function is assigned a URL at which it can receive requests. HTTP triggers support the GET, POST, PUT, DELETE, and OPTIONS request methods.

In Cloud Functions, requests to a function URL always require HTTPS.

By default, requests to a function with an HTTP trigger require authentication. You can choose to allow unauthenticated calls during deployment. See Allowing unauthenticated HTTP function invocation for more information.

You use HTTP functions to implement Cloud Functions that can handle general HTTP(S) requests.

Deployment

You can specify an HTTP trigger when you deploy a function. See Deploy a Cloud Function for general instructions on how to deploy a function, and this section for additional information specific to configuring HTTP triggers during deployment.

gcloud

If you are deploying using the gcloud CLI, the flags shown here are used to configure HTTP triggers:

gcloud functions deploy YOUR_FUNCTION_NAME \
--trigger-http \
[--allow-unauthenticated] \
[--security-level=SECURITY_LEVEL] \
...

Console

If you are deploying using the Google Cloud console, you can configure an HTTP trigger in the Trigger section:

  • Under HTTPS, in the Authentication field, select an option depending on whether you want to allow unauthenticated invocations of your function. By default, authentication is required. See Authenticate for invocation for more information.

Function URL

After your function is deployed with an HTTP trigger, you can retrieve its assigned URL.

Functions have assigned URLs that have the following format. These URLs have a deterministic format, meaning that you can predict what the URL will be before you deploy the function:

https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME

Functions also have an assigned URL that is associated with the underlying Cloud Run service. These URLs do not have a deterministic format, meaning that because the second field is a random hash, you cannot predict what the URL will be before you deploy the function. Once you deploy the function the URL will remain stable, however:

https://FUNCTION_NAME-RANDOM_HASH-REGION.a.run.app

A function's cloudfunctions.net URL and run.app URL will behave in exactly the same way. They are interchangeable.

You can retrieve your function's URL(s) as follows:

gcloud

gcloud functions describe YOUR_FUNCTION_NAME \
--region=YOUR_FUNCTION_REGION \
--format="value(serviceConfig.uri)" \
...

Console

  1. Go to the Cloud Functions overview page in the Google Cloud console:

    Go to Cloud Functions

  2. Click the name of the function whose URL you want to retrieve.

  3. Click the Edit tab.

  4. View your function's URL in the Trigger section.

Next steps