Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Gatilhos HTTP (1ª geração)
No Cloud Run functions, um gatilho HTTP permite que uma função seja executada em resposta a
solicitações HTTP(S). Quando você especifica um gatilho HTTP para uma função,
um URL para receber solicitações é atribuído a ela. Os gatilhos de HTTP oferecem suporte aos
métodos de solicitação GET, POST, PUT, DELETE e OPTIONS.
Use funções HTTP
para implementar o Cloud Run functions que podem processar solicitações HTTP(S) gerais.
Implantação
É possível especificar um gatilho HTTP ao implantar uma função. Consulte Implantar o Cloud Run functions com instruções gerais sobre como implantar uma função e esta seção com mais informações específicas para configurar gatilhos HTTP durante a implantação.
gcloud
Se você estiver implantando com a gcloud CLI, as flags mostradas aqui serão usadas para configurar os gatilhos HTTP.
A flag
--trigger-http
especifica que a função usa um gatilho HTTP.
A flag
--allow-unauthenticated
especifica que a função pode ser chamada sem autenticação.
Omitir essa flag significa que as chamadas para a função exigem
autenticação. Para mais informações, consulte
Como autenticar para invocação.
A flag
--security-level
controla se o endpoint da função exige HTTPS.
O valor secure-always indica que o HTTPS é necessário e que solicitações HTTP não SSL
não são compatíveis. O valor secure-optional significa que HTTP e HTTPS
são compatíveis. O padrão é secure-always.
No campo Autenticação, selecione uma opção
se quiser permitir invocações não autenticadas da sua
função. Por padrão, a autenticação é obrigatória. Para mais informações, consulte Como autenticar para invocação.
Marque ou desmarque a caixa de seleção Requer HTTPS para controlar se o endpoint da função exige HTTPS. Se a opção não estiver selecionada,
HTTP e HTTPS serão compatíveis.
URL da função
Após a implantação da função com um gatilho HTTP, é possível recuperar o
URL atribuído a ela.
O Cloud Run functions tem URLs atribuídos com o seguinte
formato. Esses URLs têm um formato determinístico, o que significa que você pode prever qual será o URL antes de implantar a função:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-01-31 UTC."],[[["\u003cp\u003eHTTP triggers allow Cloud Run functions to execute in response to HTTP(S) requests, with support for \u003ccode\u003eGET\u003c/code\u003e, \u003ccode\u003ePOST\u003c/code\u003e, \u003ccode\u003ePUT\u003c/code\u003e, \u003ccode\u003eDELETE\u003c/code\u003e, and \u003ccode\u003eOPTIONS\u003c/code\u003e methods, and each function is assigned a unique URL for receiving requests.\u003c/p\u003e\n"],["\u003cp\u003eBy default, HTTP triggered functions require authentication, but you can configure them during deployment to allow unauthenticated access if needed.\u003c/p\u003e\n"],["\u003cp\u003eYou can deploy a function with an HTTP trigger using the \u003ccode\u003egcloud\u003c/code\u003e CLI, where you have flags to set whether authentication is needed and if the endpoint requires HTTPS, or you can do so through the Google Cloud console by selecting the HTTP option in the trigger section.\u003c/p\u003e\n"],["\u003cp\u003eAfter deployment, the function's assigned URL can be retrieved via the \u003ccode\u003egcloud\u003c/code\u003e CLI using a command, or in the console by navigating to the function's details and viewing the trigger information.\u003c/p\u003e\n"],["\u003cp\u003eCloud Run function URLs follow a predictable format, allowing users to estimate the function URL before deploying the function.\u003c/p\u003e\n"]]],[],null,["# HTTP triggers (1st gen)\n=======================\n\nIn Cloud Run functions, an HTTP trigger enables a function to run in response to\nHTTP(S) requests. When you specify an HTTP trigger for a function, the function\nis assigned a URL at which it can receive requests. HTTP triggers support the\n`GET`, `POST`, `PUT`, `DELETE`, and `OPTIONS` request methods.\n\nBy default, requests to a function with an HTTP trigger require\n[authentication](/functions/1stgendocs/securing/authenticating). You can choose to\nallow unauthenticated calls during [deployment](#deployment). See\n[Allowing unauthenticated HTTP function invocation](/functions/1stgendocs/securing/managing-access-iam#allowing_unauthenticated_http_function_invocation)\nfor more information.\n\nYou use [HTTP functions](/functions/1stgendocs/writing/write-http-functions)\nto implement Cloud Run functions that can handle general HTTP(S) requests.\n\nDeployment\n----------\n\nYou can specify an HTTP trigger when you deploy a function. See\n[Deploy a Cloud Run function](/functions/1stgendocs/deploy) for\ngeneral instructions on how to deploy a function, and this section for\nadditional information specific to configuring HTTP triggers during deployment. \n\n### gcloud\n\nIf you are\n[deploying using the gcloud CLI](/functions/1stgendocs/deploy#gcloud),\nthe flags shown here are used to configure HTTP triggers: \n\n```sh\ngcloud functions deploy YOUR_FUNCTION_NAME \\\n--no-gen2 \\\n--trigger-http \\\n[--allow-unauthenticated] \\\n[--security-level=SECURITY_LEVEL] \\\n...\n```\n\n- The [`--trigger-http`](/sdk/gcloud/reference/functions/deploy#--trigger-http) flag specifies that the function uses an HTTP trigger.\n- The [`--allow-unauthenticated`](/sdk/gcloud/reference/functions/deploy#--allow-unauthenticated) flag specifies that the function can be called without authentication. Omitting this flag means that calls to the function require authentication. See [Authenticating for invocation](/functions/1stgendocs/securing/authenticating) for more information.\n- The [`--security-level`](/sdk/gcloud/reference/functions/deploy#--security-level) flag controls whether the function endpoint requires HTTPS. The value `secure-always` means HTTPS is required and non-SSL HTTP requests are not supported. The value `secure-optional` means both HTTP and HTTPS are supported. The default is `secure-always`.\n\n### Console\n\nIf you are\n[deploying using the Google Cloud console](/functions/1stgendocs/deploy#console),\nyou can configure an HTTP trigger in the **Trigger** section:\n\n1. In the **Trigger type** field, select **HTTP**.\n2. 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 [Authenticating for invocation](/functions/1stgendocs/securing/authenticating) for more information.\n3. Select or clear the **Require HTTPS** checkbox to control whether the function endpoint requires HTTPS. If deselected, both HTTP and HTTPS are supported.\n\nFunction URL\n------------\n\nAfter your function is deployed with an HTTP trigger, you can retrieve its\nassigned URL.\n\nCloud Run functions have assigned URLs that have the following\nformat. These URLs have a deterministic format, meaning that you can predict\nwhat the URL will be before you deploy the function: \n\n```sh\nhttps://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME\n```\n\nYou can retrieve your function's URL(s) as follows: \n\n### gcloud\n\n\u003cbr /\u003e\n\n```sh\n gcloud functions describe YOUR_FUNCTION_NAME \n\n --format=\"value(httpsTrigger.url)\"\n \n```\n\n\u003cbr /\u003e\n\n### Console\n\n1. Go to the Cloud Run functions overview page in the Google Cloud console:\n\n [Go to Cloud Run functions](https://console.cloud.google.com/functions/list)\n2. Click the name of the function whose URL you want to retrieve.\n\n3. Click the Edit tab.\n\n4. View your function's URL in the **Trigger** section.\n\nNext steps\n----------\n\n- Learn how to [write HTTP functions](/functions/1stgendocs/writing/write-http-functions).\n- Learn how to [deploy a Cloud Run function](/functions/1stgendocs/deploy).\n- See the [HTTP function tutorial](/functions/1stgendocs/tutorials/http-1st-gen) for an example of writing, deploying, and calling an HTTP function."]]