Cloud Endpoints Frameworks provides API management features that are comparable to the features that the Extensible Service Proxy (ESP) provides for Cloud Endpoints. Endpoints Frameworks includes a built-in API gateway that intercepts all requests and performs any necessary checks, such as authentication, before forwarding the request to the API backend. When the backend responds, Endpoints Frameworks gathers and reports telemetry. You can view metrics for your API on the Endpoints > Services page in the Google Cloud console.
The API management features available in Endpoints Frameworks include:
For your API to be managed by Endpoints, you must deploy an OpenAPI document that describes your API using version 2.0 of the OpenAPI Specification. This page describes how to generate and deploy an OpenAPI document that enables Endpoints to manage your API.
If you don't add API management, your API still serves requests, but your API doesn't appear on the Endpoints > Services page in the Google Cloud console, and the functionality provided by Endpoints, such as logging, monitoring, and setting quotas, isn't available.
To add API management to your API:
Set up your Maven
pom.xml
file or your Gradlebuild.gradle
file as described in Configuring the build files.Make sure that you set the Google Cloud project ID in the build files.
Maven
Search for
<endpoints.project.id>
, and replaceYOUR_PROJECT_ID
with your Google Cloud project ID. For example:<endpoints.project.id>example-project-12345</endpoints.project.id>
Gradle
-
Search for
def projectId
, and replaceYOUR_PROJECT_ID
with your Google Cloud project ID. For example:def projectId = 'example-project-12345'
-
Make sure your
build.gradle
file contains thereplaceProjectId
task, which sets the project ID in theappengine-web.xml
andweb.xml
files.
-
Search for
In your API project's
web.xml
file, add the API management servlet filter configuration:Modify your API project's build configuration:
Maven
-
Add the API management dependencies:
-
Include the plugin that you can use to generate client libraries and the OpenAPI document,
openapi.json
:
Gradle
-
Add the API management dependencies:
-
Declare the external dependency so that the plugin is retrieved from Maven Central:
-
Use the server-side Endpoints Frameworks Gradle plugin, which generates the OpenAPI document:
-
Configure the name of your Endpoints service:
-
After modifying dependencies, clean your project and then build your API:
Maven
mvn clean mvn package
Gradle
gradle clean gradle build
Generate the OpenAPI document,
openapi.json
:Maven
mvn endpoints-framework:openApiDocs
Gradle
gradle endpointsOpenApiDocs
Deploy the OpenAPI document:
gcloud endpoints services deploy openapi.json
The first time you deploy
openapi.json
, a new Endpoints service is created with the nameYOUR_PROJECT_ID.appspot.com
. On successful completion, a line similar to the following displays the service configuration ID and the service name:Service Configuration 2017-02-13r0 uploaded for service example-project-12345.appspot.com
In the preceding example,
2017-02-13r0
is the service configuration ID. The service configuration ID consists of a date stamp followed by a revision number. If you deployopenapi.json
again, the revision number is incremented in the service configuration ID.If you need to display the service configuration ID again, run the following command, but replace
YOUR_PROJECT_ID
with the project ID of your Google Cloud project:gcloud endpoints configs list --service=YOUR_PROJECT_ID.appspot.com
You can create your own OpenAPI document and deploy it, rather than using a generated one. Simply replace
openapi.json
above with the path to your OpenAPI document. For more information on writing an OpenAPI document, see OpenAPI overview.Edit your
appengine-web.xml
file to set the value for an environment variable:Replace
${endpoints.project.id}
with your Google Cloud project ID. For example:<env-var name="ENDPOINTS_SERVICE_NAME" value="example-project-12345.appspot.com" />
Redeploy your application.
Maven
mvn appengine:deploy
Gradle
gradle appengineDeploy
Test your API by making some requests to it.
To view your API metrics, open the Endpoints > Services page in the Google Cloud console for your project: