Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Cloud Endpoints Frameworks offre funzionalità di gestione delle API paragonabili a quelle fornite da Extensible Service Proxy (ESP) per Cloud Endpoints. Endpoints Frameworks include un gateway API integrato che intercetta tutte le richieste ed esegue i controlli necessari, ad esempio l'autenticazione, prima di inoltrare la richiesta al backend API. Quando il backend
risponde, Endpoints Frameworks raccoglie e segnala la telemetria. Puoi
visualizzare le metriche per la tua API nella pagina Endpoints > Servizi della
consoleGoogle Cloud .
Le funzionalità di gestione delle API disponibili in Endpoints Frameworks includono:
Perché la tua API venga gestita da Endpoints, devi eseguire il deployment di un documento OpenAPI che descriva la tua API utilizzando la versione 2.0 della specifica OpenAPI.
Questa pagina descrive come generare ed eseguire il deployment di un documento OpenAPI che consente a Endpoints di gestire la tua API.
Se non aggiungi la gestione API, la tua API continua a gestire le richieste, ma non viene visualizzata nella pagina Endpoints > Servizi della consoleGoogle Cloud e la funzionalità fornita da Endpoints, come logging, monitoraggio e impostazione delle quote, non è disponibile.
Per aggiungere la gestione delle API alla tua API:
Dopo aver modificato le dipendenze, pulisci il progetto e poi crea l'API:
Maven
mvnclean
mvnpackage
Gradle
gradleclean
gradlebuild
Genera il documento OpenAPI, openapi.json:
Maven
mvnendpoints-framework:openApiDocs
Gradle
gradleendpointsOpenApiDocs
Esegui il deployment del documento OpenAPI:
gcloudendpointsservicesdeployopenapi.json
La prima volta che esegui il deployment di openapi.json, viene creato un nuovo servizio Endpoints con il nome YOUR_PROJECT_ID.appspot.com. Al termine, viene visualizzata una riga simile alla seguente, in cui sono visualizzati l'ID configurazione del servizio e il nome del servizio:
Service Configuration 2017-02-13r0 uploaded for service example-project-12345.appspot.com
Nell'esempio precedente, 2017-02-13r0 è l'ID di configurazione del servizio. L'ID configurazione del servizio è composto da un timestamp seguito da un
numero di revisione. Se esegui di nuovo il deployment di openapi.json, il numero di revisione viene incrementato nell'ID configurazione del servizio.
Se devi visualizzare di nuovo l'ID configurazione del servizio, esegui il seguente comando, ma sostituisci YOUR_PROJECT_ID con l'ID progetto del tuo progetto Google Cloud :
gcloud endpoints configs list --service=YOUR_PROJECT_ID.appspot.com
Puoi creare e implementare il tuo documento OpenAPI anziché
utilizzarne uno generato. Basta sostituire openapi.json sopra con il percorso del tuo documento OpenAPI. Per saperne di più sulla creazione di un documento OpenAPI,
consulta la
panoramica di OpenAPI.
Modifica il file appengine-web.xml per impostare il valore di una variabile di ambiente:
[[["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-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"]]