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.
Pour ajouter la gestion des API à votre API, procédez comme suit :
Recherchez def projectId, puis remplacez YOUR_PROJECT_ID par l'ID de votre projet Google Cloud . Exemple :
def projectId = 'example-project-12345'
Assurez-vous que votre fichier build.gradle contient la tâche replaceProjectId, qui définit l'ID du projet dans les fichiers appengine-web.xml et web.xml.
Après avoir modifié les dépendances, nettoyez le projet, puis créez votre API :
Maven
mvnclean
mvnpackage
Gradle
gradleclean
gradlebuild
Générer le document OpenAPI, openapi.json :
Maven
mvnendpoints-framework:openApiDocs
Gradle
gradleendpointsOpenApiDocs
Déployez le document OpenAPI :
gcloudendpointsservicesdeployopenapi.json
Après le premier déploiement du service openapi.json, 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 précédent, 2017-02-13r0 est 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 openapi.json, le numéro de révision est incrémenté dans l'ID de configuration du service.
Si vous devez afficher à nouveau l'ID de configuration du service, exécutez la commande suivante, mais remplacez YOUR_PROJECT_ID par l'ID de votre projet Google Cloud :
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 openapi.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.
Modifiez votre fichier appengine-web.xml pour définir la valeur d'une variable d'environnement :
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 an API gateway that handles authentication and other checks before routing requests to the API backend, similar to the Extensible Service Proxy (ESP).\u003c/p\u003e\n"],["\u003cp\u003eEndpoints Frameworks offers API management features such as monitoring, logging, quotas, and a developer portal, all accessible through the Google Cloud console's Endpoints Services page.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize API management with Endpoints, you must deploy an OpenAPI document (version 2.0) that defines your API.\u003c/p\u003e\n"],["\u003cp\u003eAdding API management involves configuring build files (Maven or Gradle), setting the Google Cloud project ID, adding servlet filter configurations in \u003ccode\u003eweb.xml\u003c/code\u003e, and modifying dependencies and the build configuration.\u003c/p\u003e\n"],["\u003cp\u003eAfter building the API and generating the OpenAPI document, you have to deploy it and redeploy the application, to then view the API metrics in the Google Cloud console.\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\nTo add API management to your API:\n\n1. Set up your Maven `pom.xml` file or your Gradle `build.gradle` file as\n described in\n [Configuring the build files](/endpoints/docs/frameworks/java/set-up-environment#configuring_the_build_files).\n\n2. Make sure that you set the Google Cloud project ID in the\n build files.\n\n ### Maven\n\n Search for `\u003cendpoints.project.id\u003e`, and replace\n \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with your\n Google Cloud project ID. For example:\n\n `\u003cendpoints.project.id\u003eexample-project-12345\u003c/endpoints.project.id\u003e`\n\n\n \u003cendpoints.project.id\u003eYOUR_PROJECT_ID\u003c/endpoints.project.id\u003e\n\n \u003cbr /\u003e\n\n ### Gradle\n\n 1. Search for `def projectId`, and replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with your Google Cloud project ID. For example:\n\n `def projectId = 'example-project-12345'`\n 2. Make sure your `build.gradle` file contains the `replaceProjectId` task, which sets the project ID in the `appengine-web.xml` and `web.xml` files.\n\n\n task replaceProjectId(type: Copy) {\n from 'src/main/webapp/WEB-INF/'\n include '*.xml'\n into \"build/exploded-${archivesBaseName}/WEB-INF\"\n expand(endpoints:[project:[id:projectId]])\n filteringCharset = 'UTF-8'\n }\n\n \u003cbr /\u003e\n\n3. In your API project's `web.xml` file, add the API management servlet filter\n configuration:\n\n \u003c!-- Add a filter that fetches the service config from service management. --\u003e\n \u003cfilter\u003e\n \u003cfilter-name\u003eendpoints-api-configuration\u003c/filter-name\u003e\n \u003cfilter-class\u003ecom.google.api.control.ServiceManagementConfigFilter\u003c/filter-class\u003e\n \u003c/filter\u003e\n\n \u003c!-- Add a filter that performs Endpoints logging and monitoring. --\u003e\n \u003cfilter\u003e\n \u003cfilter-name\u003eendpoints-api-controller\u003c/filter-name\u003e\n \u003cfilter-class\u003ecom.google.api.control.extensions.appengine.GoogleAppEngineControlFilter\u003c/filter-class\u003e\n \u003cinit-param\u003e\n \u003cparam-name\u003eendpoints.projectId\u003c/param-name\u003e\n \u003cparam-value\u003e${endpoints.project.id}\u003c/param-value\u003e\n \u003c/init-param\u003e\n \u003cinit-param\u003e\n \u003cparam-name\u003eendpoints.serviceName\u003c/param-name\u003e\n \u003cparam-value\u003e${endpoints.project.id}.appspot.com\u003c/param-value\u003e\n \u003c/init-param\u003e\n \u003c/filter\u003e\n\n \u003cfilter-mapping\u003e\n \u003cfilter-name\u003eendpoints-api-configuration\u003c/filter-name\u003e\n \u003cservlet-name\u003eEndpointsServlet\u003c/servlet-name\u003e\n \u003c/filter-mapping\u003e\n\n \u003cfilter-mapping\u003e\n \u003cfilter-name\u003eendpoints-api-controller\u003c/filter-name\u003e\n \u003cservlet-name\u003eEndpointsServlet\u003c/servlet-name\u003e\n \u003c/filter-mapping\u003e\n\n4. Modify your API project's build configuration:\n\n ### Maven\n\n 1. Add the API management dependencies:\n\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.endpoints\u003c/groupId\u003e\n \u003cartifactId\u003eendpoints-management-control-appengine-all\u003c/artifactId\u003e\n \u003cversion\u003e1.0.14\u003c/version\u003e\n \u003c/dependency\u003e\n\n 2. Include the plugin that you can use to generate client libraries\n and the OpenAPI document, `openapi.json`:\n\n \u003cplugin\u003e\n \u003cgroupId\u003ecom.google.cloud.tools\u003c/groupId\u003e\n \u003cartifactId\u003eendpoints-framework-maven-plugin\u003c/artifactId\u003e\n \u003cversion\u003e2.1.0\u003c/version\u003e\n \u003cconfiguration\u003e\n \u003c!-- plugin configuration --\u003e\n \u003chostname\u003e${endpoints.project.id}.appspot.com\u003c/hostname\u003e\n \u003c/configuration\u003e\n \u003c/plugin\u003e\n\n ### Gradle\n\n 1. Add the API management dependencies:\n\n compile 'com.google.endpoints:endpoints-management-control-appengine:1.0.14'\n compile 'com.google.endpoints:endpoints-framework-auth:1.0.14'\n\n 2. Declare the external dependency so that the plugin is\n retrieved from Maven Central:\n\n classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:2.1.0'\n\n 3. Use the server-side Endpoints Frameworks Gradle plugin,\n which generates the OpenAPI document:\n\n apply plugin: 'com.google.cloud.tools.endpoints-framework-server'\n\n 4. Configure the name of your Endpoints service:\n\n endpointsServer {\n // Endpoints Framework Plugin server-side configuration\n hostname = \"${projectId}.appspot.com\"\n }\n\n5. After modifying dependencies, clean your project and then build your API:\n\n ### Maven\n\n ```bash\n mvn clean\n mvn package\n ```\n\n ### Gradle\n\n ```bash\n gradle clean\n gradle build\n ```\n6. Generate the OpenAPI document, `openapi.json`:\n\n ### Maven\n\n ```bash\n mvn endpoints-framework:openApiDocs\n ```\n\n ### Gradle\n\n ```bash\n gradle endpointsOpenApiDocs\n ```\n7. Deploy the OpenAPI document:\n\n gcloud endpoints services deploy openapi.json\n\n The first time you deploy `openapi.json`, a new Endpoints\n service is created with the name\n \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e`.appspot.com`. On\n successful completion, a line similar to the following displays\n the service configuration ID and the service name:\n\n \u003cbr /\u003e\n\n ```\n Service Configuration 2017-02-13r0 uploaded for service example-project-12345.appspot.com\n ```\n\n In the preceding example, `2017-02-13r0` is the service configuration\n ID. The service configuration ID consists of a date stamp followed by a\n revision number. If you deploy `openapi.json` again, the revision number is\n incremented in the service configuration ID.\n\n If you need to display the service configuration ID again, run the following\n command, but replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with the\n project ID of your Google Cloud project: \n\n ```\n gcloud endpoints configs list --service=YOUR_PROJECT_ID.appspot.com\n ```\n\n You can create your own OpenAPI document and deploy it, rather than\n using a generated one. Simply replace `openapi.json` above with the path to\n your OpenAPI document. For more information on writing an OpenAPI document,\n see\n [OpenAPI overview](/endpoints/docs/openapi/openapi-overview).\n8. Edit your `appengine-web.xml` file to set the value for an environment\n variable:\n\n \u003cenv-variables\u003e\n \u003cenv-var name=\"ENDPOINTS_SERVICE_NAME\" value=\"${endpoints.project.id}.appspot.com\" /\u003e\n \u003c/env-variables\u003e\n\n Replace `${endpoints.project.id}` with your Google Cloud project ID.\n For example: \n\n \u003cenv-var name=\"ENDPOINTS_SERVICE_NAME\" value=\"example-project-12345.appspot.com\" /\u003e\n\n9. Redeploy your application.\n\n \u003cbr /\u003e\n\n ### Maven\n\n ```java\n mvn appengine:deploy\n ```\n\n ### Gradle\n\n ```java\n gradle appengineDeploy\n ```\n\n \u003cbr /\u003e\n\n10. Test your API by making some requests to it.\n\n11. 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"]]