Molti dei comandi gcloud mostrati richiedono di specificare l'ID dell'API, nel formato: API_ID.
API Gateway applica i seguenti requisiti per l'ID API:
Deve avere una lunghezza massima di 63 caratteri.
Deve contenere solo lettere minuscole, numeri o trattini.
Non deve iniziare con un trattino.
Non deve contenere un trattino basso.
Creazione di un'API
Per creare un'API:
Convalida l'ID progetto restituito dal seguente comando per assicurarti che il servizio non venga creato nel progetto sbagliato.
gcloud config list project
Se devi modificare il progetto predefinito, esegui il seguente comando
e sostituisci PROJECT_ID con l' Google Cloud ID progetto
in cui vuoi creare il servizio::
gcloud config set project PROJECT_ID
Se l'ID progetto contiene due punti (:), consulta
Progetti basati sul dominio per ulteriori dettagli sulla creazione di un' API nel progetto.
Google Cloud CLI accetta molte opzioni, tra cui quelle descritte nella documentazione di riferimento di gcloud. Inoltre, per API Gateway puoi impostare le seguenti opzioni durante la creazione di un'API:
--async: restituisce immediatamente il controllo al terminale, senza attendere il completamento dell'operazione.
--display-name=NAME: specifica il nome visualizzato dell'API, ovvero il nome mostrato nell'interfaccia utente. Non utilizzare spazi nel nome. Utilizza i trattini e i trattini bassi. Il valore predefinito è API_ID.
--labels=KEY1=VALUE1,KEY2=VALUE2,...: specifica le etichette associate alla configurazione dell'API.
--managed-service: specifica un servizio gestito preesistente (ad esempio un servizio Endpoints esistente) per l'API.
Progetti basati su dominio
Se il progetto è limitato al tuo dominio, l'ID progetto include il nome del dominio seguito da due punti (:), ad esempio example.com:my-project. Devi fornire un servizio gestito valido quando crei un'API in un progetto a livello di dominio.
Se utilizzi gcloud, fornisci il nome del servizio gestito utilizzando il flag --managed-service, come descritto in Opzioni gcloud.
API di schede
Per elencare tutte le API in un progetto:
gcloud api-gateway apis list --project=PROJECT_ID
Questo comando restituisce l'output nel seguente formato:
NAME DISPLAY_NAME MANAGED_SERVICE STATE
projects/PROJECT_ID/locations/global/apis/API_IDAPI_IDMANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog ACTIVE
Utilizza l'ID progetto e l'ID API per ottenere informazioni dettagliate sull'API:
Dopo la creazione, puoi aggiornare le etichette e il nome visualizzato di un'API esistente.
Utilizza le seguenti opzioni gcloud per aggiornare un'API esistente:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-03 UTC."],[[["\u003cp\u003eBefore creating an API, ensure your development environment is properly configured and meets the API ID requirements, which include a maximum length of 63 characters, lowercase letters, numbers, or dashes, and no starting dashes or underscores.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003egcloud api-gateway apis create API_ID --project=PROJECT_ID\u003c/code\u003e command to create a new API, where you specify the desired API ID and the Google Cloud project ID.\u003c/p\u003e\n"],["\u003cp\u003eAfter creation, the API's display name and labels can be updated using the \u003ccode\u003egcloud api-gateway apis update\u003c/code\u003e command with options like \u003ccode\u003e--display-name\u003c/code\u003e, \u003ccode\u003e--update-labels\u003c/code\u003e, \u003ccode\u003e--clear-labels\u003c/code\u003e, and \u003ccode\u003e--remove-labels\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo delete an API, you must first delete all associated API configs using \u003ccode\u003egcloud api-gateway api-configs delete\u003c/code\u003e, and then delete the API itself with \u003ccode\u003egcloud api-gateway apis delete\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eListing all the existing APIs within a project can be done with the following command \u003ccode\u003egcloud api-gateway apis list --project=PROJECT_ID\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Creating an API\n===============\n\nPrerequisites\n-------------\n\nBefore you can create an API on API Gateway, ensure that you have:\n\n- Prepared your development environment as described in [Configuring your development environment](/api-gateway/docs/configure-dev-env).\n\nAPI ID requirements\n-------------------\n\nMany of the `gcloud` commands shown require you to specify the ID of the API, in the form: \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e.\nAPI Gateway enforces the following requirements for the API ID:\n\n- Must have a maximum length of 63 characters.\n- Must contain only lowercase letters, numbers, or dashes.\n- Must not start with a dash.\n- Must not contain an underscore.\n\nCreating an API\n---------------\n\nTo create an API:\n\n1. Validate the project ID returned from the following command to make sure that\n the service isn't created in the wrong project.\n\n ```\n gcloud config list project\n ```\n\n If you need to change the default project, run the following command\n and replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with the Google Cloud project ID\n in which you want to create the service:: \n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n If your project ID contains a colon (`:`), see\n [Domain-scoped projects](#domain) for additional details about creating an\n API in your project.\n2. View help for the `apis create` command:\n\n ```\n gcloud api-gateway apis create --help\n ```\n3. Run the following command to create the API:\n\n ```\n gcloud api-gateway apis create API_ID --project=PROJECT_ID\n ```\n\n where:\n - \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e specifies the ID of the new API. See [API ID requirements](#api-id-requirements) for API naming guidelines.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e specifies the Google Cloud project ID.\n\n As it is creating the API, API Gateway outputs information to the terminal.\n4. On successful completion, you can use the following command to view details about the new API:\n\n ```\n gcloud api-gateway apis describe API_ID --project=PROJECT_ID\n ```\n\n This command returns the following: \n\n ```scdoc\n createTime: '2020-02-29T21:52:20.297426875Z'\n displayName: API_ID\n managedService: MANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog\n name: projects/PROJECT_ID/locations/global/apis/API_ID\n state: ACTIVE\n updateTime: '2020-02-29T21:52:20.647923711Z'\n ```\n\n### gcloud options\n\nThe Google Cloud CLI takes many options, including those described in the\n[gcloud Reference](/sdk/gcloud/reference). In addition,\nfor API Gateway, you can set the following options when creating an API:\n\n- `--async`: Return control to the terminal immediately, without waiting for the operation to complete.\n- `--display-name=`\u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e: Specifies the display name of the API, meaning the name shown in the UI. Do not use spaces in the name. Use hyphens and underscores instead. The default value is \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e.\n- `--labels=`\u003cvar translate=\"no\"\u003eKEY1\u003c/var\u003e`=`\u003cvar translate=\"no\"\u003eVALUE1\u003c/var\u003e`,`\u003cvar translate=\"no\"\u003eKEY2\u003c/var\u003e`=`\u003cvar translate=\"no\"\u003eVALUE2\u003c/var\u003e`,...`: Specifies labels associated with the API config.\n- `--managed-service`: Specifies a pre-existing managed service (for example, an existing Endpoints service) for the API.\n\n### Domain-scoped projects\n\nIf your project is scoped to your domain, the project ID includes the name of\nthe domain followed by a colon (`:`), for example, `example.com:my-project`. You\nmust provide a valid managed service when creating an API in a domain-scoped\nproject.\n\nIf using `gcloud`, provide the managed service name using the\n`--managed-service` flag, as described in\n[gcloud options](#gcloud-options).\n| **Note:** Scoping projects to a domain is a legacy feature. You cannot create new domain-scoped projects.\n\nListing APIs\n------------\n\nTo list all APIs in a project: \n\n```\ngcloud api-gateway apis list --project=PROJECT_ID\n```\n\nThis command returns output in the form: \n\n```scdoc\nNAME DISPLAY_NAME MANAGED_SERVICE STATE\nprojects/PROJECT_ID/locations/global/apis/API_ID API_ID MANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog ACTIVE\n```\n\nUse the project ID and API ID to obtain detailed information about the API: \n\n```\ngcloud api-gateway apis describe API_ID --project=PROJECT_ID\n```\n\nUpdating an API\n---------------\n\nAfter creation, you can update the labels and display name of an existing API.\nUse the following `gcloud` options to update an existing API:\n\n- `--display-name`\n- `--update-labels`\n- `--clear-labels`\n- `--remove-labels`\n\nFor example: \n\n```\ngcloud api-gateway apis update API_ID --project=PROJECT_ID \\\n --update-labels=a=1,b=2\n```\n\nUse the following command to view all update options: \n\n```\ngcloud api-gateway apis update --help\n```\n\nDeleting an API\n---------------\n\nTo delete an API you must:\n\n- Delete the API configs associated with the API.\n- Delete the API.\n\n| **Note:** If you deployed an API config to a gateway, then deleting the API causes the gateway to stop serving traffic. However, you are not required to delete the gateway. Instead, you can deploy an API config from a different API to the gateway.\n\nTo delete an API:\n\n1. Determine the list of API configs associated with the API:\n\n ```\n gcloud api-gateway api-configs list --api=API_ID --project=PROJECT_ID\n ```\n2. Delete each API config associated with the API:\n\n ```\n gcloud api-gateway api-configs delete CONFIG_ID --api=API_ID --project=PROJECT_ID\n ```\n3. Delete the API:\n\n ```\n gcloud api-gateway apis delete API_ID --project=PROJECT_ID\n ```\n\nWhat's next\n-----------\n\n- [Creating an API config](/api-gateway/docs/creating-api-config)"]]