Quickstart: Deploy an API managed by Cloud Endpoints  |  Google Cloud (2024)

This QuickStart walks you through deploying a sample API, whichEndpoints manages. The sample code includes:

  • A REST API that you can query to find the name of an airport from itsthree-letter IATA code.
  • A script that uploads the API configuration to Endpoints.
  • A script that deploys an App Engine flexible environment backend to host thesample API.

After you send requests to the sample API, you can view theEndpoints activity graphs and Google Cloud Observability logs in theGoogle Cloud console. These tools let you monitor your APIs and gain insights intotheir usage.

This QuickStart uses scripts to simplify the configuration steps for you toquickly see the activity graphs and logs in action. To learn how toconfigure and deploy a sample API, choose a tutorial for one of the APIframeworks:

  • Cloud Endpoints for OpenAPI: Tutorials
  • Cloud Endpoints for gRPC: Tutorials
  • Cloud Endpoints Frameworks: Tutorials

Before you begin

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

Starting Cloud Shell

  1. In the Google Cloud console, make sure you are in the project that youwant to use for the sample API.

  2. Open Cloud Shell.

    Open Cloud Shell

    A Cloud Shell session opens inside a new frame at the bottom of theGoogle Cloud console and displays a command-line prompt. It can take a fewseconds for the session to initialize.

    Quickstart: Deploy an API managed by Cloud Endpoints | Google Cloud (1)

  3. If you're using an existing project, make sure you have the latest version ofall installed gcloud components:

    gcloud components update

Getting the sample code

  1. In Cloud Shell, enter the following command to get the sample APIand scripts:

    git clone https://github.com/GoogleCloudPlatform/endpoints-quickstart
  2. Change to the directory that contains the sample code:

    cd endpoints-quickstart

Deploying the Endpoints configuration

To publish a REST API to Endpoints, an OpenAPI configuration filethat describes the API is required. The sample API comes with a pre-configuredOpenAPI file called openapi.yaml.

Endpoints uses Service Management, an infrastructure service ofGoogle Cloud to create and manage APIs and services. To useEndpoints to manage an API, you deploy the API's OpenAPIconfiguration file to Service Management.

To deploy the Endpoints configuration:

  1. In Cloud Shell, in the endpoints-quickstart directory, enter thefollowing:

    cd scripts
  2. Run the following script, which is included in the sample:

    ./deploy_api.sh

Endpoints uses the host field in the OpenAPI configuration fileto identify the service. The deploy_api.sh script sets the ID of yourGoogle Cloud project as part of the name configured in the host field.When you prepare an OpenAPI configuration file for your own service, you need todo this manually.

The script then deploys the OpenAPI configuration to Service Managementby using the command: gcloud endpoints services deploy openapi.yaml

As it is creating and configuring the service, Service Management outputsinformation to the Google Cloud console. You can safely ignore the warningsabout the paths in openapi.yaml not requiring an API key. On successfulcompletion, you see a line similar to the following that displays the serviceconfiguration ID and the service name:

 Service Configuration [2017-02-13-r2] uploaded for service [airports-api.endpoints.example-project.cloud.goog]

Enabling required services

At a minimum, Endpoints requires the following Google services to be enabled:

NameTitle
servicemanagement.googleapis.comService Management API
servicecontrol.googleapis.comService Control API
endpoints.googleapis.comGoogle Cloud Endpoints

In most cases, deploying the Endpoints configuration enables theserequired services.

Use the following command to confirm that the required services are enabled:

gcloud services list

If you do not see the required services listed, enable them:

gcloud services enable servicemanagement.googleapis.comgcloud services enable servicecontrol.googleapis.comgcloud services enable endpoints.googleapis.com

Also enable your Endpoints service:

gcloud services enable YOUR-PROJECT-ID.appspot.com

For more information about the gcloud commands, seegcloud services.

Deploying the API backend

So far you have deployed the OpenAPI configuration to Service Management,but you haven't yet deployed the code to serve the API backend. Thedeploy_app.sh script included in the sample creates an App Engineflexible environment to host the API backend, and then the script deploys theAPI to App Engine.

To deploy the API backend:

  • In Cloud Shell, in the endpoints-quickstart/scripts directory, runthe following script:

    ./deploy_app.sh

The script runs the following command to create an App Engine flexibleenvironment in the us-central region:gcloud app create --region="$REGION"

It takes several minutes to create the App Engine flexible environmentbackend. After the application is created, the output is:

Success! The app is now created.

Next, the script runs the gcloud app deploy command todeploy the sample API to App Engine.

The output is:

Deploying ../app/app_template.yaml...You are about to deploy the following services:

It takes several minutes to deploy the API to App Engine. When the API issuccessfully deployed to App Engine, the output is:

Deployed service [default] to [https://example-project.appspot.com]

Sending requests to the API

The script echoes the curl command that it uses to send a request to the API,and then displays the result. The output is:

curl "https://example-project.appspot.com/airportName?iataCode=SFO"San Francisco International Airport

The API expects one query parameter, iataCode, that is set to a valid IATAairport code such as SEA or JFK. For example:

./query_api.sh JFK

Note: App Engine may take a few minutes torespond successfully to requests. If you send a request and get anHTTP 502, 503, or some other server error, wait a minute andtry the request again.

You just deployed and tested an API in Endpoints!

Tracking API activity

With APIs deployed with Endpoints, you can monitor criticaloperations metrics in the Google Cloud console, and gain insight into yourusers and usage with Cloud Logging.

  1. In Cloud Shell, run the traffic generation script to populate thegraphs and logs:

    ./generate_traffic.sh
  2. In the Google Cloud console, look at the activity graphs for your API.

    Go to the Endpoints Services page

    It might take a few moments for the requests to be reflected in the graphs.While you wait for data to be displayed:

    • If the Permissions side panel isn't open, click +Permissions.The Permissions panel lets youcontrol who has accessto your API and the level of access.

    • Click Deployment history. This tab displays a history of yourAPI deployments, including the deployment time and who deployed thechange.

    • Click Overview. You see the traffic coming in. After the trafficgeneration script has been running for a minute, you see three lineson the Total latency graph (50th, 95th, and 98th percentiles). Thisdata provides an estimate of response times.

  3. Scroll down to the table below the graphs, and under Links,click View Logs for GET/airportName. The Logs Explorer pagedisplays the request logs for the API.

  4. Open Cloud Shell.

    Open Cloud Shell

  5. To stop the script, enter Control+C.

Adding a quota to the API

Endpoints lets you set quotas that let you control the rate atwhich applications can call your API. You can use quotas to protect your APIfrom excessive usage by a single client.

  1. In Cloud Shell, deploy the Endpoints configurationthat has a quota.

    ./deploy_api.sh ../openapi_with_ratelimit.yaml

    After you deploy an updated Endpoints configuration, itbecomes active within a minute.

  2. In the Google Cloud console, go to the Credentials page.

    Go to the Credentials page

  3. Click Create credentials, and then click API key. A new API key isdisplayed on the screen.

  4. Click Copy file_copy.

  5. In Cloud Shell, type the following. ReplaceYOUR_API_KEY with the API key youjust created.

    export API_KEY=YOUR_API_KEY
  6. Send your API a request using the API key you just generated.

    ./query_api_with_key.sh $API_KEY

    The output is similar to the following:

    curl -H 'x-api-key: AIzeSyDbdQdaSdhPMdiAuddd_FALbY7JevoMzAB' "https://example-project.appspot.com/airportName?iataCode=SFO"San Francisco International Airport
  7. The API now has a limit of 5 requests per minute. Run the following commandto send traffic to the API and trigger the quota limit.

    ./generate_traffic_with_key.sh $API_KEY
  8. After running the script for 5-10 seconds, enter Control+C to stop the script.

  9. Send another authenticated request to the API.

    ./query_api_with_key.sh $API_KEY

    The output is similar to the following:

    { "code": 8, "message": "Insufficient tokens for quota 'airport_requests' and limit 'limit-on-airport-requests' of service 'example-project.appspot.com' for consumer 'api_key:AIzeSyDbdQdaSdhPMdiAuddd_FALbY7JevoMzAB'.", "details": [ { "@type": "type.googleapis.com/google.rpc.DebugInfo", "stackEntries": [], "detail": "internal" } ]}

If you get a different response, try running the generate_traffic_with_key.shscript again and then retry.

Congratulations! You've successfully rate-limited your API. You can also setvarying limits on different API methods, create multiple kinds of quotas, andkeep track of which consumers use which APIs.

For more information, seeAbout quotas.

Creating a developer portal for the API

You can use Cloud Endpoints Portal to create a developer portal, a websitethat you can use to interact with the sample API. To learn more, seeCloud Endpoints Portal overview.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

To avoid incurring charges, you can delete your Google Cloud project to stopbilling for all the resources used within that project.

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next

  • For on overview of Endpoints:

    • About Endpoints
    • Endpoints: Architectural overview
  • To learn about the different API frameworks that Endpointssupports:

    • The OpenAPI Specification
    • Endpoints for gRPC APIs
    • About Endpoints Frameworks
  • To learn how to configure and deploy a sample API, choose a tutorial for oneof the API frameworks:

    • Endpoints for OpenAPI: Tutorials
    • Endpoints for gRPC: Tutorials
    • Endpoints Frameworks: Tutorials
Quickstart: Deploy an API managed by Cloud Endpoints  |  Google Cloud (2024)
Top Articles
Airbnb vs VRBO - Which Is More Profitable?
How Much Money Can a Mobile App Make in 2024 | Orangesoft
San Angelo, Texas: eine Oase für Kunstliebhaber
Lakers Game Summary
Hotels
Monthly Forecast Accuweather
Occupational therapist
Fort Carson Cif Phone Number
Coindraw App
Craigslist Vermillion South Dakota
Routing Number 041203824
Espn Expert Picks Week 2
William Spencer Funeral Home Portland Indiana
Blog:Vyond-styled rants -- List of nicknames (blog edition) (TouhouWonder version)
The Witcher 3 Wild Hunt: Map of important locations M19
Star Wars: Héros de la Galaxie - le guide des meilleurs personnages en 2024 - Le Blog Allo Paradise
Mahpeople Com Login
If you bought Canned or Pouched Tuna between June 1, 2011 and July 1, 2015, you may qualify to get cash from class action settlements totaling $152.2 million
Doublelist Paducah Ky
Yisd Home Access Center
Morse Road Bmv Hours
Village
Engineering Beauties Chapter 1
Which Sentence is Punctuated Correctly?
Cpt 90677 Reimbursem*nt 2023
Cb2 South Coast Plaza
Craigslist Dubuque Iowa Pets
Watertown Ford Quick Lane
12657 Uline Way Kenosha Wi
Ravens 24X7 Forum
Newcardapply Com 21961
What Are Digital Kitchens & How Can They Work for Foodservice
The best Verizon phones for 2024
When His Eyes Opened Chapter 2048
Indiana Jones 5 Showtimes Near Cinemark Stroud Mall And Xd
Electronic Music Duo Daft Punk Announces Split After Nearly 3 Decades
Anhedönia Last Name Origin
Henry Ford’s Greatest Achievements and Inventions - World History Edu
Author's Purpose And Viewpoint In The Dark Game Part 3
Sofia With An F Mugshot
Jamesbonchai
Free Crossword Puzzles | BestCrosswords.com
Walmart 24 Hrs Pharmacy
Bonecrusher Upgrade Rs3
Race Deepwoken
Who Is Nina Yankovic? Daughter of Musician Weird Al Yankovic
Tìm x , y , z :a, \(\frac{x+z+1}{x}=\frac{z+x+2}{y}=\frac{x+y-3}{z}=\)\(\frac{1}{x+y+z}\)b, 10x = 6y và \(2x^2\)\(-\) \(...
Ret Paladin Phase 2 Bis Wotlk
Suzanne Olsen Swift River
Escape From Tarkov Supply Plans Therapist Quest Guide
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 5844

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.