Building REST APIs in Google Cloud

Fermin Blanco
Google Cloud - Community
3 min readSep 10, 2023

--

Cloud Computing

Abstract

API development is a crucial part in modern web applications. APIs enable communication between services, applications and end users. APIs allows applications to expose data and/or functionality to other services.

Let’s use Go 1.21

Stop this madness and show me the code!

Go API handlers

API handlers association to paths

Services

You can deploy an API in Google Cloud using a variety of services, including:

  • Cloud Endpoints: Distribute management API system. Provides logs and metrics, API hosting and authorization.
  • Google App Engine: This is a fast, scalable, and easy-to-set-up and maintain method.

To deploy an API in Google Cloud, you can:

  1. Create an OpenAPI spec that describes your API.
  2. Configure the routes to your Cloud Run backend service.
  3. Deploy your API configuration.
  4. Deploy your Backend API.

Cloud endpoints

Cloud endpoints ese the distribute Extensible Service Proxy to serve APIs with low latency and high performance. Provides a convenient way to take care of APIs management tasks such as authorization, monitoring and rate limiting.

OpenAPI Spec

Drawback

If your service was deployed to the App Engine flexible environment,

you had to re-deploy your service every time you deployed changes to the API configuration, even if there were no changes to the source code

App Engine Flexible Environment (Go)

For versions 1.18 and later are built using buildpacks. This enables you to choose an operating system.

Runtime Configuration

Buildpacks are group together into collections called builders that can,

  1. Analyze project source code
  2. Create a build plan
  3. Generate a container image

App.yaml

This file acts as a deployment descriptor of a specific service version.

App.yaml

If you’re interested in learning more about building APIs in Google Cloud, please stay tune to my upcoming articles.

Common Issues

cannot find module for path io/fs

This was a funny issue since you need to set a specify version of the Go runtime for the build flow to works.

(gcloud.app.deploy) INVALID_ARGUMENT: You may not have more than 32 total max instances in your project.

In the manual_scallingconfiguration set the instances to 1.

Manual Scaling Configuration

Resources

--

--