La plupart des commandes gcloud présentées nécessitent de spécifier l'ID de l'API, au format suivant: API_ID.
API Gateway applique les exigences suivantes pour l'ID d'API :
Doit comporter 63 caractères maximum.
Ne doit contenir que des lettres minuscules, des chiffres ou des tirets.
Il ne doit pas commencer par un tiret.
Il ne doit pas contenir de trait de soulignement.
Créer une API
Pour créer une API :
Validez l'ID de projet renvoyé par la commande suivante, afin de vous assurer que le service est créé dans le projet correct.
gcloud config list project
Si vous devez changer le projet par défaut, exécutez la commande suivante et remplacez PROJECT_ID par l' Google Cloud ID du projet dans lequel vous souhaitez créer le service :
gcloud config set project PROJECT_ID
Si l'ID de votre projet contient un signe deux-points (:), consultez la section Projets à l'échelle du domaine pour en savoir plus sur la création d'une API dans votre projet.
La Google Cloud CLI accepte de nombreuses options, y compris celles décrites dans la documentation de référence gcloud. De plus, pour API Gateway, vous pouvez définir les options suivantes lorsque vous créez une API:
--async : rend le contrôle immédiatement au terminal, sans attendre la fin de l'opération.
--display-name=NAME: spécifie le nom à afficher de l'API, c'est-à-dire le nom affiché dans l'UI. N'utilisez pas d'espaces dans le nom. Utilisez plutôt des traits d'union et des traits de soulignement. La valeur par défaut est API_ID.
--labels=KEY1=VALUE1,KEY2=VALUE2,... : spécifie les libellés associés à la configuration d'API.
--managed-service : spécifie un service géré préexistant (par exemple, un service Endpoints existant) pour l'API.
Projets à l'échelle du domaine
Si votre projet est à l'échelle de votre domaine, l'ID de projet comprend le nom du domaine suivi par un deux-points (:), par exemple example.com:my-project. Vous devez fournir un service géré valide lorsque vous créez une API dans un projet de portée de domaine.
Si vous utilisez gcloud, indiquez le nom du service géré à l'aide de l'indicateur --managed-service, comme décrit dans les options gcloud.
API de listing
Pour répertorier toutes les API d'un projet, procédez comme suit :
gcloud api-gateway apis list --project=PROJECT_ID
Cette commande renvoie un résultat au format suivant :
NAME DISPLAY_NAME MANAGED_SERVICE STATE
projects/PROJECT_ID/locations/global/apis/API_IDAPI_IDMANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog ACTIVE
Utilisez l'ID du projet et l'ID de l'API pour obtenir des informations détaillées sur l'API :
Après la création, vous pouvez modifier les libellés et le nom à afficher d'une API existante.
Utilisez les options gcloud suivantes pour mettre à jour une API existante:
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/03 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)"]]