This page describes how to deploy your API.

## Before you begin

- [Set up your programming environment](https://docs.cloud.google.com/endpoints/docs/frameworks/java/set-up-environment.md.txt).
- [Create an API](https://docs.cloud.google.com/endpoints/docs/frameworks/java/annotate-code.md.txt) and annotate it.

## Deploying an API

You can deploy your API using the App Engine
[Apache Maven](https://docs.cloud.google.com/appengine/docs/standard/java/using-maven)
or [Gradle](https://docs.cloud.google.com/appengine/docs/standard/java/using-gradle) plugins. To deploy your
API to a production App Engine standard environment, use the command for
your plugin:

1. Use the command for your plugin:

   ### Maven

   ```bash
   mvn appengine:deploy
   ```

   ### Gradle

   ```bash
   gradle appengineDeploy
   ```
2. Wait for the deployment to finish.
3. Send a test request to your deployed API. For example, using `curl`:

   ```java
   curl \
       -H "Content-Type: application/json" \
       -X POST \
       -d '{"message": "echo"}' \
       "https://YOUR-PROJECT-ID.appspot.com/_ah/api/echo/v1/echo?n=2"
   ```

   Your response is similar to the following:

   ```
   {
     "message": "echo echo"
   }
   ```

If you didn't get a successful response, see
[Troubleshooting response errors](https://docs.cloud.google.com/endpoints/docs/frameworks/troubleshoot-response-errors.md.txt).

## Deploying to multiple application versions

For information on how to do API versioning, and how to deploy to versions,
see [Handling API versioning](https://docs.cloud.google.com/endpoints/docs/frameworks/java/handling-api-versioning.md.txt)

## Running and testing API backends locally

To test your API locally:

1. Build the project in the root directory of the project. For example:

   ### Maven

   ```bash
   mvn clean package
   ```

   ### Gradle

   ```bash
   gradle clean build
   ```
2. Start the App Engine development server. For example:

   ### Maven

   ```bash
   mvn appengine:run
   ```

   ### Gradle

   ```bash
   gradle appengineRun
   ```
3. Make an API request to test your API. For example, using `curl`:

   ```java
   curl \
       -H "Content-Type: application/json" \
       -X POST \
       -d '{"message": "echo"}' \
       "${HOST}/_ah/api/echo/v1/echo?n=2"
   ```

## Serving your API from a different path

To serve your API from a different path, in your `web.xml` file, change the
`url-pattern` in the `EndpointsServlet` section and redeploy your API. For
example:

```java
<servlet-mapping>
    <servlet-name>EndpointsServlet</servlet-name>
    <url-pattern>/example-api/*</url-pattern>
</servlet-mapping>
```

## Adding API management

Endpoints Frameworks provides API management features such as:

- [Monitoring](https://docs.cloud.google.com/endpoints/docs/frameworks/monitoring-your-api.md.txt)
- [Logging](https://docs.cloud.google.com/endpoints/docs/frameworks/monitoring-your-api.md.txt#logs)
- [Quotas](https://docs.cloud.google.com/endpoints/docs/openapi/quotas-overview.md.txt)
- [Developer portal](https://docs.cloud.google.com/endpoints/docs/openapi/dev-portal-overview)

For your API to be managed by Endpoints Frameworks, you must generate
and deploy an OpenAPI document that describes your API, as described in
[Adding API management](https://docs.cloud.google.com/endpoints/docs/frameworks/java/adding-api-management.md.txt).