Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Google Cloud: API Gateway Basic Tutorials

Below is a practical, step-by-step Google Cloud API Gateway setup using a dummy backend on Cloud Run (hello service), then testing via curl. This follows Googleโ€™s official โ€œAPI Gateway + Cloud Runโ€ flow. (Google Cloud Documentation)


0) Prereqs

  • A Google Cloud project + billing enabled
  • Google Cloud SDK (gcloud) installed and logged in

Set variables (edit these 4 lines):

export PROJECT_ID="YOUR_PROJECT_ID"
export REGION="us-central1"
export API_ID="demo-api"
export GATEWAY_ID="demo-gw"
gcloud config set project "$PROJECT_ID"
Code language: JavaScript (javascript)

1) Enable required APIs

gcloud services enable \
  apigateway.googleapis.com \
  cloudbuild.googleapis.com \
  run.googleapis.com
Code language: CSS (css)

(API Gateway requires its service enabled; Cloud Run/Cloud Build are used for the dummy backend.) (Google Cloud Documentation)


2) Deploy a dummy backend on Cloud Run

Deploy a public โ€œhelloโ€ container:

gcloud run deploy hello-backend \
  --image gcr.io/cloudrun/hello \
  --region "$REGION" \
  --allow-unauthenticated
Code language: JavaScript (javascript)

Get the Cloud Run URL:

export BACKEND_URL="$(gcloud run services describe hello-backend --region "$REGION" --format='value(status.url)')"
echo "$BACKEND_URL"
Code language: PHP (php)

Quick test the backend directly:

curl -i "$BACKEND_URL"
Code language: JavaScript (javascript)

3) Create an OpenAPI spec for API Gateway

Create a file openapi.yaml (Swagger/OpenAPI 2.0) like this:

swagger: "2.0"
info:
  title: "Demo API Gateway"
  description: "API Gateway -> Cloud Run dummy backend"
  version: "1.0.0"

schemes:
  - https

produces:
  - application/json

paths:
  /hello:
    get:
      operationId: hello
      x-google-backend:
        address: BACKEND_URL_REPLACE_ME
      responses:
        "200":
          description: OK
Code language: PHP (php)

Replace BACKEND_URL_REPLACE_ME with your Cloud Run URL:

sed -i.bak "s|BACKEND_URL_REPLACE_ME|$BACKEND_URL|g" openapi.yaml
Code language: JavaScript (javascript)

Why this works: API Gateway reads x-google-backend to know where to route requests. (Google Cloud Documentation)


4) Create an API config (uploads your OpenAPI to API Gateway)

export API_CONFIG_ID="demo-config-v1"

gcloud api-gateway api-configs create "$API_CONFIG_ID" \
  --api="$API_ID" \
  --openapi-spec=openapi.yaml \
  --project="$PROJECT_ID"
Code language: JavaScript (javascript)

Creating an API config is the โ€œupload the definitionโ€ step. (Google Cloud Documentation)


5) Create a Gateway and deploy the config

gcloud api-gateway gateways create "$GATEWAY_ID" \
  --api="$API_ID" \
  --api-config="$API_CONFIG_ID" \
  --location="$REGION" \
  --project="$PROJECT_ID"
Code language: JavaScript (javascript)

This deploys the API config to a gateway. (Google Cloud Documentation)


6) Get the Gateway URL and test

Fetch the gatewayโ€™s default hostname:

export GATEWAY_HOST="$(gcloud api-gateway gateways describe "$GATEWAY_ID" --location "$REGION" --format='value(defaultHostname)')"
echo "$GATEWAY_HOST"
Code language: PHP (php)

Call your API through API Gateway:

curl -i "https://${GATEWAY_HOST}/hello"
Code language: JavaScript (javascript)

You should see a response coming from the Cloud Run hello backend (but accessed via the gateway).


Optional: Require an API Key (simple protection)

API Gateway can enforce API keys using security definitions. (Google Cloud Documentation)

A) Update openapi.yaml to require API key

Add these blocks:

securityDefinitions:
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"

security:
  - api_key: []
Code language: JavaScript (javascript)

(Keep your /hello path the same.)

B) Create a NEW config and deploy it

export API_CONFIG_ID="demo-config-v2"

gcloud api-gateway api-configs create "$API_CONFIG_ID" \
  --api="$API_ID" \
  --openapi-spec=openapi.yaml

gcloud api-gateway gateways update "$GATEWAY_ID" \
  --location "$REGION" \
  --api="$API_ID" \
  --api-config="$API_CONFIG_ID"
Code language: JavaScript (javascript)

C) Create an API key in Google Cloud Console and test

Call without key (should fail), then with key:

curl -i "https://${GATEWAY_HOST}/hello?key=YOUR_API_KEY"
Code language: JavaScript (javascript)

Cleanup (avoid charges)

gcloud api-gateway gateways delete "$GATEWAY_ID" --location "$REGION" -q
gcloud api-gateway api-configs delete demo-config-v1 --api "$API_ID" -q || true
gcloud api-gateway api-configs delete demo-config-v2 --api "$API_ID" -q || true
gcloud api-gateway apis delete "$API_ID" -q
gcloud run services delete hello-backend --region "$REGION" -q
Code language: JavaScript (javascript)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Ruby on Rails vs Node.js: Performance, Speed, and Scalability Compared

Choosing between Ruby on Rails and Node.js is a common decision when building modern web applications. Both frameworks power large-scale products, but they approach performance, concurrency, and…

Read More

How Zero-Knowledge Coprocessors Are Reshaping Web3 Computation

Developers often hit a brick wall when building decentralized apps. Standard infrastructure just fails to keep up. Clogging a main network with heavy workloads leads to slow…

Read More

5 Top Developer Experience (DevEx) Insight Tools for 2026

Developer experience has evolved from an internal engineering concern into a measurable operational discipline. As software organizations scale across distributed cloud environments, platform engineering initiatives, AI-assisted development…

Read More

Top 10 AI Tools to Automate Repetitive Documents For DevOps Teamsย 

DevOps teams have automated deployingโ€š testingโ€š monitoringโ€š and rolling back changesโ€š but documentation layer automation is a gap that still incurs time costโ€ค Gartner predicts by 2026…

Read More

Customer Loyalty Strategy for SaaS and eCommerce: How to Pick the Right Software

Customer Loyalty Strategy for SaaS and eCommerce: How to Pick the Right Software TL;DR Retaining a customer costs 5 to 25 times less than acquiring a new…

Read More

Top 10 Sales Enablement Tools: Features, Pros, Cons & Comparison

Introduction Sales Enablement Tools are platforms designed to equip sales teams with the right content, insights, training, and data at the right timeโ€”so they can sell more…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Skylar Bennett
Skylar Bennett
5 months ago

This article provides a clear and practical introduction to Google Cloud API Gateway, making it easier for readers to understand how to manage, secure, and scale APIs in cloud environments. The step-by-step explanations help demystify key concepts like routing, authentication, and traffic control, which are essential for building resilient services. With API-driven architectures becoming central to modern applications, learning these fundamentals equips developers and architects to design efficient, secure, and scalable systems with confidence.

1
0
Would love your thoughts, please comment.x
()
x