This page describes how to deploy your API.

## Before you begin

- [Set up your programming environment and download tools](https://docs.cloud.google.com/endpoints/docs/frameworks/python/get-started-frameworks-python.md.txt#before-you-begin).
- [Create your API](https://docs.cloud.google.com/endpoints/docs/frameworks/python/create_api.md.txt).
- [Create a web server](https://docs.cloud.google.com/endpoints/docs/frameworks/python/api_server.md.txt) to serve your API.

## Deploying your API to production

To deploy an API:

1. Set the `ENDPOINTS_GAE_SDK` environment variable to the path of your
   App Engine SDK folder:
   `Path_to_Cloud_SDK/platform/google_appengine`.

   Replace `Path_to_Cloud_SDK` with the output of the
   following command:

   ```python
    gcloud info --format="value(installation.sdk_root)"
   ```
2. Run the following command in the API main directory:

   ```python
    gcloud app deploy
   ```

   Wait a few moments for the deployment to succeed, ignoring the warning
   messages. When the deployment completes, a message similar to the
   following displays:

   ```
   File upload done.
   Updating service [default]...done.
   ```
3. Confirm successful deployment by sending a test request to the API, for
   example:

   ```
   curl --request POST \
      --header "Content-Type: application/json" \
      --data '{"content":"echo"}' \
      https://PROJECT_ID.appspot.com/_ah/api/echo/v1/echo?n=2
   ```

   Replace `PROJECT_ID` with your project ID and
   `echo` with your API name.

   The results are:

   ```
   {
    "content": "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 app 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/python/handling-api-versioning.md.txt)

## Testing an API locally

You can use the App Engine local development server to test your API
locally. For more information about the local development server, see
[Using the local development server](https://docs.cloud.google.com/appengine/docs/standard/python/tools/using-local-server).

To run your API locally:

1. From the root directory of the project, start the App Engine
   development server:

   ```
   dev_appserver.py YOUR_PROJECT_DIR
   ```
2. Run `curl` to make an API request, for example:

   ```python
    curl --request POST \
       --header "Content-Type: application/json" \
       --data '{"message":"echo"}' \
       "${HOST}/_ah/api/echo/v1/echo?n=2"
   ```

## 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/python/adding-api-management.md.txt).