This page describes how to set up your development environment to build and deploy your backend API using Cloud Endpoints Frameworks for the App Engine standard environment. This page uses the Endpoints Frameworks version 2.0 skeleton code sample to explain the basic software and components you need to get started.
You might want to use the
endpoints-skeleton-archetype
or the hello-endpoints-archetype
described in
Using Apache Maven and the App Engine plugin (Google Cloud CLI-based)
to create a new Endpoints Frameworks version 2.0 project.
To get a better understanding of the steps required to deploy a sample API using Endpoints Frameworks, see the tutorial Getting started with Endpoints Frameworks on App Engine.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
- Make a note of the Google Cloud project ID because it is needed later.
Installing and configuring required software
- If you don't have Java 8 installed, download the Java Development Kit (JDK) from Oracle's site and install it.
- Install either Maven or Gradle:
Maven
- Download Apache Maven version 3.3.9 or greater
- Install and configure Maven for your local development environment.
Gradle
- Download and initialize the Google Cloud CLI.
- Run the following commands:
- Make sure that the gcloud CLI is authorized to access your data and services on Google Cloud:
gcloud auth login
- Use application default credentials:
gcloud auth application-default login
- Install the Google Cloud SDK
app-engine-java
component:gcloud components install app-engine-java
- Update to the latest version of the Google Cloud SDK and all components:
gcloud components update
- Make sure that the gcloud CLI is authorized to access your data and services on Google Cloud:
- Create an App Engine application:
-
Set the default project to your Google Cloud project ID:
gcloud config set project YOUR_PROJECT_ID
Replace
YOUR_PROJECT_ID
with your Google Cloud project ID. If you have other Google Cloud projects, and you want to usegcloud
to manage them, see Managing gcloud CLI configurations. - Select the region where you want to create your App Engine application. See App Engine locations for a list of regions.
- Create an App Engine application.
Replace
YOUR_PROJECT_ID
with your Google Cloud project ID andYOUR_REGION
with the region that you want the App Engine application created in.gcloud app create \ --project=YOUR_PROJECT_ID \ --region=YOUR_REGION
-
Set the default project to your Google Cloud project ID:
Getting the Endpoints Frameworks skeleton sample
The Endpoints Frameworks version 2.0 skeleton sample contains the necessary build scripts for Maven and Gradle. It also contains the required files to get started creating your first API.
Clone the sample repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
Change to the directory containing the Endpoints Frameworks skeleton sample:
cd java-docs-samples/appengine-java8/endpoints-v2-skeleton/
The sample has the following directory structure:
MyApi.java
contains an empty class that you can use to get started writing your API. See the echo example for sample code to help you get started.web.xml
is a standard file that is used to configure a servlet.appengine-web.xml
defines information that is required to deploy the API to the App Engine standard environment by using Java 8.pom.xml
contains project and configuration information used by Maven to build the project and deploy the API to App Engine.build.gradle
contains project and configuration information used by Gradle to build the project and deploy the API to App Engine.
Configuring the build files
This section describes the Maven pom.xml
and Gradle build.gradle
files
included in the sample code. Except for entering your Google Cloud project
ID so that it can be used in the hostname, the build files are ready for you to
get started creating your API.
About the minimum configuration
This section describes the minimum configuration needed in your build file.
Maven
Minimum dependencies
The following shows the minimum dependencies required in your
pom.xml
to get started:
- The
endpoints-framework
dependency contains the necessary classes for creating your API. - You need the App Engine Standard API
SDK (
appengine-api-sdk
) to deploy your project to the App Engine standard environment. - The standard
javax.servlet
package is required to build a servlet. - The standard
javax.inject
package is required to support dependency injection.
Apply plugins
The following plugins are applied to enable them:
- The
maven-war-plugin
extends thejava
plugin to add support for assembling a web application. - The
appengine-maven-plugin
is required to run the API on App Engine. - The
endpoints-framework-maven-plugin
provides tasks and configurations to build Endpoints Frameworks projects.
Gradle
Plugin dependencies
The following shows the plugins required to build your API:
- The Endpoints Frameworks Gradle plugin is used to generate an OpenAPI document and to generate client libraries.
- You need the App Engine Gradle plugin to deploy your project to App Engine.
Apply plugins
The following plugins are applied to enable them in your Gradle build script:
- The
java
plugin adds Java-specific compilation and build steps to your project. - The
war
plugin extends thejava
plugin to add support for assembling a web application. - The
endpoints-framework-server
plugin provides server-side support to the Endpoints Frameworks Gradle plugin. - The
appengine
plugin is required to run the API on App Engine.
Project dependencies
The following dependencies are used by the project:
- The
endpoints-framework
dependency contains the necessary classes for creating your API. - The App Engine Standard
API SDK (
appengine-api-sdk
) is needed to deploy your project to the App Engine standard environment. - The standard
javax.servlet
package is required to build a servlet. - The standard
javax.inject
package is required to support dependency injection.
Defining the hostname for your service
Endpoints Frameworks uses DNS-compatible names to uniquely identify services. Because Google Cloud project IDs are guaranteed to be globally unique, you should use your Google Cloud project ID as part of your API's service name.
You must add your Google Cloud project ID to the build files to configure the hostname for your service. The hostname should be in the following format:
YOUR_PROJECT_ID.appspot.com
When you deploy the API to App Engine, a DNS entry with a name in the
format YOUR_PROJECT_ID.appspot.com
is created automatically. The hostname is
both the name of the Cloud Endpoints service and the domain name that you use
to send requests to your API.
Maven
In the hostname
field, replace
YOUR_PROJECT_ID
with your Google Cloud project
ID.
Gradle
Set the variable projectID
to your Google Cloud
project ID. For example:
def projectId = 'example-project-12345'
Configuring the Endpoints servlet
The Endpoints servlet handles incoming requests and forwards them to the backend service running on App Engine. The Endpoints servlet is required for your API to be managed by Endpoints.
For more information about web.xml
, see
The deployment descriptor: web.xml
.
Configuring your App Engine deployment
The appengine-web.xml
file is used to define the App Engine standard
environment configuration when the API is deployed. See
appengine-web.xml
reference
for more information.
What's next
- Write and annotate your backend API code.
- Learn more about annotations.
- Add API management.
- Deploy and test your API.
- Learn more about supported parameter and return types.