Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cloud Endpoints Frameworks fournit des fonctionnalités de gestion des API comparables à celles fournies par le proxy Extensible Service Proxy (ESP) pour Cloud Endpoints. Endpoints Frameworks comprend une passerelle API intégrée qui intercepte toutes les requêtes et effectue les vérifications nécessaires (telles que l'authentification) avant de transmettre la requête au backend de l'API. Lorsque le backend répond, Endpoints Frameworks rassemble et consigne les données de télémétrie. Vous pouvez afficher les métriques de votre API sur la page Endpoints > Services de la consoleGoogle Cloud .
Les fonctionnalités de gestion des API disponibles dans Endpoints Frameworks comprennent :
Pour que votre API soit gérée par Endpoints, vous devez déployer un document OpenAPI décrivant votre API à l'aide de la version 2.0 de la spécification OpenAPI.
Cette page explique comment générer et déployer un document OpenAPI permettant à Endpoints de gérer votre API.
Si vous n'ajoutez pas la gestion des API, votre API diffuse toujours les requêtes, mais elle ne figure pas sur la page Endpoints > Services de la consoleGoogle Cloud . De plus, les fonctionnalités fournies par Endpoints, telles que la journalisation, la surveillance et la définition de quotas, ne sont pas disponibles.
Installer et configurer le logiciel requis
Si vous ne l'avez pas déjà fait, installez et configurez la Google Cloud CLI pour Python. Ensuite, ajoutez la bibliothèque Endpoints Frameworks pour Python à votre répertoire de projet API afin qu'elle soit importée avec le code de l'API lors du déploiement.
Installez le composant gcloud qui inclut l'extension App Engine pour Python :
gcloudcomponentsinstallapp-engine-python
Mettre à jour gcloud CLI :
gcloudcomponentsupdate
Assurez-vous que la CLI gcloud est autorisée à accéder à vos données et services sur Google Cloud:
gcloudauthlogin
Un nouvel onglet de navigateur vous invite à choisir un compte.
Définissez le projet par défaut sur votre ID de projet. Remplacez YOUR_PROJECT_ID par l'ID de votre Google Cloud projet.
gcloud config set project YOUR_PROJECT_ID
Pour Linux, définissez la variable d'environnement ENDPOINTS_GAE_SDK sur le chemin d'accès au dossier de votre SDK App Engine :
PATH_TO_CLOUD_SDK/platform/google_appengine
Remplacez PATH_TO_CLOUD_SDK par le résultat de la commande suivante :
gcloudinfo--format="value(installation.sdk_root)"
Ajouter la bibliothèque Endpoints Frameworks pour Python
Assurez-vous de pouvoir compiler des extensions C pour Python.
Windows : le compilateur Microsoft Visual C++ 9.0 (ou version ultérieure) est requis. Vous pouvez télécharger le compilateur Microsoft Visual C++ pour Python 2.7 depuis le centre de téléchargement Microsoft.
Autres systèmes d'exploitation : en fonction de votre système d'exploitation, vous devrez peut-être installer des outils de compilation (parfois dans un package appelé build-essential) et/ou les en-têtes de développement Python (parfois dans un package appelé python-dev).
Modifiez le répertoire pour sélectionner le répertoire principal de votre API.
Créez un sous-répertoire /lib dans le répertoire principal de l'API :
mkdirlib
Installez la bibliothèque :
pipinstall-tlibgoogle-endpoints--ignore-installed
Générer le document OpenAPI
Dans le répertoire principal de l'API, générez un document OpenAPI à l'aide des outils de framework. Exemple :
Une seule classe
Dans la commande suivante, remplacez YOUR_PROJECT_ID par votre ID de projet Google Cloud .
Vous pouvez répertorier plusieurs classes sur la ligne de commande. Endpoints génère un document OpenAPI pour chaque combinaison de nom et version de l'API.
Si vous souhaitez déployer plusieurs classes d'API avec des noms d'API différents dans le cadre d'un même service, vous devez également ajouter l'option --x-google-api-name.
L'activation de cet indicateur ajoute des restrictions supplémentaires concernant les noms de vos API. Plus précisément, les noms doivent correspondre à l'expression régulière [a-z][a-z0-9]{0,39}. En d'autres termes, le nom doit être composé de 1 à 40 caractères, qui peuvent tous être soit des lettres minuscules, soit des chiffres (à l'exception du premier caractère, qui ne doit pas être un chiffre). Exemple :
Dans la commande suivante, remplacez YOUR_PROJECT_ID par l'ID de votre Google Cloud projet.
Endpoints utilise le texte spécifié dans l'argument hostname en tant que nom de service. Lorsque vous déployez l'API sur App Engine, une entrée DNS portant un nom au format YOUR_PROJECT_ID.appspot.com est créée automatiquement.
Déployer le document OpenAPI
Une seule classe
gcloudendpointsservicesdeployechov1openapi.json
Plusieurs classes
Si vous possédez plusieurs documents OpenAPI, répertoriez-les tous sur la ligne de commande.
Exemple :
Après le premier déploiement de vos documents OpenAPI, un service Endpoints est créé sous le nom YOUR_PROJECT_ID.appspot.com.
Si l'opération réussit, une ligne semblable à la suivante affiche l'ID de configuration du service et le nom du service :
Service Configuration 2017-02-13r0 uploaded for service example-project-12345.appspot.com
Dans l'exemple ci-dessus, 2017-02-13r0 correspond à l'ID de configuration du service. L'ID de configuration du service se compose d'un horodatage, suivi d'un numéro de révision. Si vous déployez à nouveau votre document OpenAPI, le numéro de révision est ajouté à l'ID de configuration du service.
Si vous devez afficher à nouveau l'ID de configuration du service, exécutez la commande suivante en remplaçant YOUR_PROJECT_ID par l'ID de votre Google Cloud projet:
gcloud endpoints configs list --service=YOUR_PROJECT_ID.appspot.com
Vous pouvez créer votre propre document OpenAPI et le déployer plutôt que d'utiliser un document généré. Il vous suffit pour cela de remplacer l'élément echov1openapi.json ci-dessus par le chemin d'accès à votre document OpenAPI. Pour en savoir plus sur la rédaction d'un document OpenAPI, consultez la page Présentation d'OpenAPI.
Redéployer et tester votre API
Modifiez la section app.yaml du fichier de votre projet et ajoutez une section env_variables comme suit :
Remplacez YOUR_PROJECT_ID par votre ID de projetGoogle Cloud et YOUR_SERVICE_VERSION par votre ID de configuration de service comme défini dans la section précédente. Si vous ajoutez ces éléments au fichier app.yaml, Endpoints gère votre API après le redéploiement de votre application.
Redéployez votre application.
gcloudappdeploy
Attendez que le déploiement soit terminé, en ignorant les messages d'avertissement. Une fois le déploiement terminé, un message semblable au suivant s'affiche :
Fileuploaddone.Updatingservice[default]...done.
Effectuez un test pour constater si le redéploiement s'est effectué avec succès, par exemple en utilisant curl :
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/04 (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/04 (UTC)."],[[["\u003cp\u003eCloud Endpoints Frameworks provides API management features, including monitoring, logging, quotas, and a developer portal, similar to the Extensible Service Proxy (ESP) for Cloud Endpoints.\u003c/p\u003e\n"],["\u003cp\u003eTo manage an API with Endpoints, you must deploy an OpenAPI document (version 2.0) that describes the API, enabling functionalities such as logging, monitoring, and setting quotas.\u003c/p\u003e\n"],["\u003cp\u003eInstalling the Google Cloud CLI, along with the App Engine extension for Python and adding the Endpoints Frameworks Python library to your project, is necessary for configuring the development environment.\u003c/p\u003e\n"],["\u003cp\u003eGenerating an OpenAPI document with the framework tools, using commands such as \u003ccode\u003epython lib/endpoints/endpointscfg.py get_openapi_spec\u003c/code\u003e, allows for either single or multiple class API descriptions, deployable through the gcloud CLI.\u003c/p\u003e\n"],["\u003cp\u003eAfter deploying the OpenAPI document and redeploying the API, make sure to edit the \u003ccode\u003eapp.yaml\u003c/code\u003e file with the \u003ccode\u003eENDPOINTS_SERVICE_NAME\u003c/code\u003e and \u003ccode\u003eENDPOINTS_SERVICE_VERSION\u003c/code\u003e, to confirm that Endpoints manages your API, and then use gcloud commands to test the redeployment.\u003c/p\u003e\n"]]],[],null,["# Adding API management\n\nCloud Endpoints Frameworks provides API management features that are comparable to\nthe features that the\n[Extensible Service Proxy (ESP)](/endpoints/docs/frameworks/glossary#extensible_service_proxy)\nprovides for Cloud Endpoints. Endpoints Frameworks includes a\nbuilt-in\n[API gateway](https://en.wikipedia.org/wiki/API_management)\nthat intercepts all requests and performs any necessary checks, such as\nauthentication, before forwarding the request to the API backend. When the backend\nresponds, Endpoints Frameworks gathers and reports telemetry. You can\nview metrics for your API on the **Endpoints** \\\u003e **Services** page in the\nGoogle Cloud console.\n\nThe API management features available in Endpoints Frameworks include:\n\n- [Monitoring](/endpoints/docs/frameworks/monitoring-your-api)\n- [Logging](/endpoints/docs/frameworks/monitoring-your-api#logs)\n- [Quotas](/endpoints/docs/openapi/quotas-overview)\n- [Developer portal](/endpoints/docs/openapi/dev-portal-overview)\n\nFor your API to be managed by Endpoints, you must deploy\nan OpenAPI document that describes your API using version 2.0 of the\n[OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).\nThis page describes how to generate and deploy an OpenAPI document that\nenables Endpoints to manage your API.\n\nIf you don't add API management, your API still serves requests, but your\nAPI doesn't appear on the **Endpoints** \\\u003e **Services** page in the\nGoogle Cloud console, and the functionality provided by\nEndpoints, such as logging, monitoring, and setting quotas, isn't\navailable.\n\nInstalling and configuring required software\n--------------------------------------------\n\nIf you haven't already done so, install and configure the Google Cloud CLI for\nPython, and add the Endpoints Frameworks Python library to your API\nproject directory so it is uploaded with the API code upon deployment\n\n### Install and configure the gcloud CLI for Python\n\n1. Install and initialize gcloud CLI:\n\n [Download and install gcloud CLI](/sdk/docs)\n2. Install the `gcloud` component that includes the\n App Engine extension for Python:\n\n gcloud components install app-engine-python\n\n3. Update the gcloud CLI:\n\n gcloud components update\n\n4. Make sure that the gcloud CLI is authorized to access your data and\n services on Google Cloud:\n\n gcloud auth login\n\n A new browser tab opens and you are prompted to choose an account.\n5. Set the default project to your project ID. Replace\n \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with your Google Cloud project ID.\n\n ```\n gcloud config set project YOUR_PROJECT_ID\n ```\n6. For Linux, set the `ENDPOINTS_GAE_SDK` environment variable to the path of\n your App Engine SDK folder:\n\n ```\n PATH_TO_CLOUD_SDK/platform/google_appengine\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePATH_TO_CLOUD_SDK\u003c/var\u003e with the output of\n the following command: \n\n gcloud info --format=\"value(installation.sdk_root)\"\n\n### Add the Endpoints Frameworks Python library\n\n1. Be sure you can compile C extensions for Python.\n\n - Windows: Microsoft Visual C++ 9.0 or greater is required. You can\n download the Microsoft Visual C++ Compiler for Python 2.7 from the\n [Microsoft download center](http://aka.ms/vcpython27)\n\n - Other operating systems: Depending on your operating system, you may\n need to install compiler tools (sometimes in a package called\n `build-essential`) and/or the Python development headers (sometimes in a\n package called `python-dev`).\n\n2. Change directory to your API's main directory.\n\n3. Make a `/lib` subdirectory in the API's main directory:\n\n mkdir lib\n\n4. Install the library:\n\n pip install -t lib google-endpoints --ignore-installed\n\nGenerate the OpenAPI document\n-----------------------------\n\nFrom the API's main directory, generate an OpenAPI document by using the framework\ntools. For example: \n\n### Single Class\n\nIn the following command, replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with\nyour Google Cloud project ID. \n\n```\npython lib/endpoints/endpointscfg.py get_openapi_spec main.EchoApi \\\n --hostname YOUR_PROJECT_ID.appspot.com\n```\n\nIgnore the warnings that are displayed.\n\n### Multiple Classes\n\nYou can list multiple classes on the command line. Endpoints\ngenerates an OpenAPI document for each API name/version combination.\n\nIf you want to deploy multiple API classes with different API names as part\nof a single service, you must also add the `--x-google-api-name` flag.\nEnabling this flag adds extra restrictions on your API names. Specifically,\nthe names must match the regular expression `[a-z][a-z0-9]{0,39}`; that is,\nthe name must consist of 1-40 characters, which can all be either lowercase\nalphabetical characters or numbers, except that the first character must not\nbe a number. For example:\n\nIn the following command, replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e\nwith your Google Cloud project ID. \n\n```\npython lib/endpoints/endpointscfg.py get_openapi_spec main.FooApi main.BarApi \\\n --hostname YOUR_PROJECT_ID.appspot.com \\\n --x-google-api-name\n```\n\nIgnore the warnings that are displayed.\n\nEndpoints uses the text that you specify in the `hostname`\nargument as the service name. When you deploy the API to App Engine,\na DNS entry with a name in the format\n\u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e`.appspot.com` is created\nautomatically.\n\nDeploy the OpenAPI document\n---------------------------\n\n### Single Class\n\n gcloud endpoints services deploy echov1openapi.json\n\n### Multiple Classes\n\nIf you have multiple OpenAPI documents, list them all on the command line.\nFor example: \n\n gcloud endpoints services deploy foov1openapi.json barv1openapi.json\n\nThis first time you deploy your OpenAPI document (or documents), a new\nEndpoints service is created with the name\n\u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e`.appspot.com`.\n\nOn successful completion, a line similar to the following displays the service\nconfiguration ID and the service name: \n\n```\nService Configuration 2017-02-13r0 uploaded for service example-project-12345.appspot.com\n```\n\nIn the example above, \u003cvar translate=\"no\"\u003e2017-02-13r0\u003c/var\u003e is the service configuration\nID. The service configuration ID consists of a date stamp followed by a\nrevision number. If you deploy your OpenAPI document again, the revision\nnumber is incremented in the service configuration ID.\n\nIf you need to display the service configuration ID again, run the following\ncommand, but replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with the project ID\nof your Google Cloud project: \n\n```\ngcloud endpoints configs list --service=YOUR_PROJECT_ID.appspot.com\n```\n\nYou can create your own OpenAPI document and deploy it, rather than\nusing a generated one. Simply replace `echov1openapi.json` above with the\npath to your OpenAPI document. For more information on writing an OpenAPI\ndocument, see\n[OpenAPI overview](/endpoints/docs/openapi/openapi-overview).\n\nRedeploy your API and test\n--------------------------\n\n1. Edit your project's file `app.yaml` and add an `env_variables` section as\n follows:\n\n ```\n env_variables:\n ENDPOINTS_SERVICE_NAME: YOUR_PROJECT_ID.appspot.com\n ENDPOINTS_SERVICE_VERSION: YOUR_SERVICE_VERSION\n ```\n\n Replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with your\n Google Cloud project ID, and \u003cvar translate=\"no\"\u003eYOUR_SERVICE_VERSION\u003c/var\u003e\n with your service configuration ID from the\n previous section. With this addition to the `app.yaml` file,\n Endpoints manages your API after you\n redeploy your application.\n2. Redeploy your application:\n\n gcloud app deploy\n\n3. Wait a few moments for the deployment to succeed, ignoring the warning\n messages. When the deployment completes, a message similar to the\n following is displayed:\n\n File upload done.\n Updating service [default]...done.\n\n4. Test for a successful redeployment, for example, using curl:\n\n ```\n curl --request POST \\\n --header \"Content-Type: application/json\" \\\n --data '{\"content\":\"echo\"}' \\\n https://YOUR_PROJECT_ID.appspot.com/_ah/api/echo/v1/echo?n=2\n ```\n\n Replace `echo` with the name of your API.\n\n The results should display something similar to: \n\n {\n \"content\": \"echo echo\"\n }\n\n5. Make some additional requests to your API.\n\n6. To\n [view your API metrics](/endpoints/docs/frameworks/monitoring-your-api),\n open the **Endpoints** \\\u003e **Services** page in the Google Cloud console for your project: \n\n\n [Go to the Endpoints Services page](https://console.cloud.google.com/endpoints)\n\n \u003cbr /\u003e"]]