Deploying and Testing an API

This page describes how to deploy your API.

Before you begin

Deploying your API to production

To deploy an API:

  1. If this is the first time you are deploying the API, or if you have modified your API decorators, generate and deploy your API configuration file before deploying your API.

  2. Set the ENDPOINTS_GAE_SDK environment variable to the path of your App Engine SDK folder, for example [Path-to-Google-Cloud-SDK]/platform/google_appengine.

  3. Invoke the following command in the API main directory:

     gcloud app deploy
  4. Wait a few moments for the deployment to succeed, ignoring the warning messages. When the deployment completes, you'll see a message similar to the following:

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

     curl -H "Content-Type: application/json" -X POST -d '{"content":"echo"}' https://[PROJECT-ID]

    Replace [PROJECT-ID] with your project ID and echo with your API name.

  6. View the results: you should see:

      "content": "echo echo"

Generating and deploying an API configuration file

You must regenerate and re-deploy your API configuration when you deploy your API for the first time, and generally whenever you change configuration details in your API decorators.

To deploy the API configuration file:

  1. Make sure you have added API management to your project.

  2. From the API’s main directory, generate an OpenAPI document using the framework tools, for example:

     python lib/endpoints/ get_swagger_spec main.EchoApi --hostname

    Replace your-service with your project ID. Ignore the warnings that are displayed.

  3. Deploy the configuration file, for example:

     gcloud endpoints services deploy echov1openapi.json

    The command returns several lines of information, including a line similar to the following:

     Service Configuration with version "[2016-12-01R0]" uploaded for service "[YOUR-PROJECT-ID]"
  4. Note the service configuration version shown in the returned lines, for example in the above lines, 2016-12-01R0. you need this later in this procedure.

    You can always find the version later by invoking the command

     gcloud endpoints configs list --service=[YOUR-PROJECT-ID]

    replacing [PROJECT-ID] with your project ID.

  5. Edit your project's file app.yaml env_variables section as follows:

       # Replace with your endpoints service name.
       # Replace with the version Id of your uploaded Endpoints service.

    Replace [YOUR-PROJECT-ID] with your project ID, and [YOUR-SERVICE-VERSION] with your service configuration version from the previous step. (Do not include the square brackets.)

  6. Re-deploy your API:

     gcloud app deploy

Deploying to multiple app versions

For information on how to do API versioning, and how to deploy to versions, see Handling API Versioning

Testing an API locally

To run your API locally:

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


    Replace [PATH-TO-SDK] with the path where you installed the App Engine SDK for Python. Replace [YOUR-PROJECT-DIR] with the name of the main directory for your API, including path.

  2. Invoke curl to make an API request:

     curl \
         -H "Content-Type: application/json" \
         -X POST \
         -d '{"message": "echo"}' \

Send feedback about...

Cloud Endpoints Frameworks for App Engine