适用于AWS API Gateway的基于URI的版本控制 [英] URI-based Versioning for AWS API Gateway

查看:204
本文介绍了适用于AWS API Gateway的基于URI的版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力了解AWS API Gateway如何希望我组织API以使版本控制变得简单.例如,假设我有一个简单的API,可以从字典中获取单词,还可以选择通过查询参数过滤结果.我想在以下网址获得此版本的v1:

I am struggling to understand how AWS API Gateway wants me to organise my APIs such that versioning is straightforward. For example, let's say I have a simple API for getting words from a dictionary, optionally filtering the results by a query parameter. I'd like to have v1 of this be available at:

https://<my-domain>/v1/names?starts-with=<value>

但是,我能获得的最接近的API网关是

However, the closest I can get API Gateway is at

https://<my-domain>/names/v1?starts-with=<value>

...非常落后.

我在控制台中得到的是带有支持GET方法的"v1"资源的名称API".我还具有自定义域设置,以将名称"的基本路径映射到名称API"并进行测试".基本路径必须是唯一的,因此放置"v1"只会有一个短期胜利.一旦创建了第二个API(例如Numbers API),它也将具有v1,并且我将无法创建第二个映射.

What I've got in the console is "Names API" with a "v1" resource supporting a GET method. I also have my custom domain setup to map a base path of "names" to "Names API" and stage "test". The Base path must be unique so putting "v1" there is only a short-term win; once I create my second API (e.g. Numbers API) it'll have a v1, too, and I won't be able to create a second mapping.

由于我现在没主意了,任何帮助都将不胜感激.

Any and all help is greatly appreciated as I'm out of ideas now.

推荐答案

请勿在您的API中将版本路径(/v1)创建为资源.相反,只需调用您的API名称V1"并开始创建资源(/名称).当您要进行重大更改并创建API的新版本时,建议您创建一个名为"Names V2"的全新API.再一次,只需创建没有版本路径的资源即可.

Do not create the version path (/v1) as a resource in your API. Instead, simply call you API "Names V1" and start creating the resources (/names). When you want to make a breaking change and create a new version of the API, we recommend you create an entirely new API called "Names V2". Once again, simply create your resources without the version path.

要将两个API整合在一起,可以使用自定义域名. API Gateway中的自定义域名包括完全限定的域名和基本路径.创建两个自定义域名:

To bring the two APIs together, you can use custom domain names. A custom domain name in API Gateway includes both a fully qualified domain name and a base path. Create two custom domain names:

  • myapi.com/v1->指向Names V1 API的生产阶段
  • myapi.com/v2->指向Names V2 API的生产阶段

这样,您可以在对v2进行更改的同时保留v1的错误修复,并独立部署两个API.自定义域名会将它们组合在一起,并使它们出现在同一域(myapi.com/v2/names)下.

This way you can keep bug-fixing v1 while making changes to v2 and deploy the two APIs independently. The custom domain name will bring them together and make them appear under the same domain (myapi.com/v2/names).

希望这会有所帮助.

这篇关于适用于AWS API Gateway的基于URI的版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆