Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Multiple OpenAPI specs on the same domain - dynamically

Hi there,

I'm very new to GCP - as in, a few days - and am just getting to grips with what can and can't be done.

So far I've gotten a Cloud Function deployed, with an API Gateway fronting it so that I can have an OpenAPI spec describing the API. That was all relatively straightforward.

What I'm struggling to work out is having multiple specs under the same domain. For example:

  • /users
  • /posts
  • /comments

All as different modules (I'm using Terraform) with their own cloud functions and OpenAPI specs, but all accessed under the same domain - e.g. https://testing.example.com/users, https://testing.example.com/posts, etc.

From what I can see, each API Gateway is a single OpenAPI spec, and a single base URL. I have seen suggestions of using a Load Balancer or CDN to front multiple API Gateways behind a single base URL. However, that then gets to the second issue.

I'm wanting the ability to create and destroy ephemeral environments for testing purposes. So I can create an entire environment, run a set of tests against it, destroy the environment and then if the tests passed deploy it all to the "real" environment. That means that I'm wanting to have the ability to create this single base URL for multiple API Gateways dynamically, and *not* needing to have a dedicated domain for it.

I don't really care what the base URL is - for example, https://testing-default-api-gw-9kav87uo.uc.gateway.dev/users is perfectly fine for me. I just want to have that https://testing-default-api-gw-9kav87uo.uc.gateway.dev/ or equivalent be shared across multiple API specs and dynamically created.

Is this possible at all? And if so, how do I do it?

Cheers

0 1 493
1 REPLY 1

Hi,
Your observation is correct in that you can only deploy a single API config to a Gateway[1]. However, you can deploy multiple configs to multiple gateways within the same API[2].  

I found this feature request for the support of hosting multiple API configs[3]. I recommend starring this page and adding a comment with your use case.

[1] https://cloud.google.com/api-gateway/docs/deployment-model#multiregion

[2] https://cloud.google.com/api-gateway/docs/deployment-model#deploying_api_configs_to_multiple_gateway...

[3] https://issuetracker.google.com/169904955