重写api网关集成请求中的目标路径 [英] Rewrite destination path in api gateway integration request

查看:185
本文介绍了重写api网关集成请求中的目标路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在API网关中有一个类似于/foo/{bar}的资源.我想通过集成请求模板将请求路径转换为/bing/baz/{bar}.

Say I have a resource like: /foo/{bar} in API Gateway. I want to transform the request path to /bing/baz/{bar} via an integration request template.

直接通过以下方法将"bar"设置到请求正文中即可:

It is straight forward to set 'bar' into the request body via:

{ "bar": "$inputs.params('bar')" }

如何在请求时重写目标路径?

How do I rewrite the destination path at request time?

此解决方案在此处的示例请求响应"中得到了提示:

The solution is hinted at in 'Example Request Response' here:

https://docs. aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

,但是文档并未确切概述使用输入模板:"的功能.

but the docs don't outline exactly how 'With input template:' functions.

Resource: /things/{id}

With input template:
{
    "id" : "$input.params('id')",
    "count" : "$input.path(‘$.things').size()",
    "things" : $input.json(‘$.things')
}

推荐答案

您可能正在寻找映射模板变量'$ context.resourcePath',它将为您提供发出请求的资源路径.

You might be looking for mapping template variable '$context.resourcePath' which will give you the resource path on which the request was made.

您可以在HTTP集成的URI字段中使用路径参数,从而可以将主体中的参数或字段动态映射到目标路径.语法与资源的语法相同,因此在参数" http://myapi.com/foo之类的大括号内/bar/ {baz}".

You can use path parameters in the URI field in the HTTP integration, which allows you to dynamically map parameters or fields in the body to the destination path. The syntax is the same as for resources, so curly brackets around the parameter like "http://myapi.com/foo/bar/{baz}".

然后,您将可以为'baz'指定映射表达式.

Then you'll be able to specify a mapping expression for 'baz'.

这篇关于重写api网关集成请求中的目标路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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