AWS API网关,重写响应主体中的可发现性URL



通过API网关从外部访问EC2实例上运行的遗留微服务。微服务返回具有可发现性url选项的JSON响应:

GET/api/accout/0001

{
id: "0001",
balance: 1000000,
currency: "BTC",
_links: [
{name: "close", method: "DELETE", url: "http://10.0.0.1:8080/api/account/0001" },
{name: "deposit", method: "POST", url: "http://10.0.0.1:8080/api/account/0001/deposit" }
]
}

API网关通过https和自定义域名公开API,因此链接如下http://10.0.0.1:8080/api/account/0001"在外部毫无意义。

如何配置AWS API网关以替换"http://10.0.0.1:8080/api/account/0001"与"https://api.mycompany.com/api/account/0001"在将响应从微服务传递到外部api客户端之前?

neneneba API网关支持响应转换和方法映射功能。

您可以定义具有所需转换的响应模板:

API网关响应转换

基于此:

如果需要,添加身体映射模板以转换给定的集成响应有效载荷转换为指定的方法响应有效载荷。

使用JSON路径表达式的特定方法模型,可用于转换。

最新更新