从Amazon API网关终端节点输出纯文本内容 [英] output plain text content from Amazon API gateway endpoint

查看:120
本文介绍了从Amazon API网关终端节点输出纯文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Amazon的API网关,我可以创建一个端点,该端点将调用输出纯文本的lambda函数.但是,当我在端点上发出请求时,输出以默认内容类型"application/json"返回.这将输出用引号引起来的纯文本响应.我想将响应标头更改为"text/plain",因此它只输出未加引号的文本.有人知道该怎么做吗?

Using Amazon's API Gateway I can create an endpoint that will call a lambda function that outputs plain text. However, when I make a request on the endpoint, the output comes back with the default content type of "application/json". This outputs the plain text response wrapped in quotes. I'd like to change the response header to "text/plain" so it just outputs the text unwrapped with quotes. Does anyone know how to do this?

推荐答案

所以我设法解决了这个问题.

So I managed to get this working.

在集成响应中,您需要添加一个新的类型为文本/纯文本"的映射模板

In the Integration Response, you need to add a new Mapping Template of type "text/plain"

在框中输入模板类型:

$input.path('$')

或者是您要返回并保存新映射模板的值的路径(请勿选择模型!)

Or the path to the value you want to return and save the new Mapping Template (do not select a model!)

然后,您将需要重新部署API,以使更改生效.

You will then need to re-deploy your API for the change to take effect.

我已经准备就绪的一件事是,方法响应也使用Empty模型设置为文本/纯文本".我不确定这是否有效果,但是如果以上方法无效,只需将其添加进来即可.

One thing I had in place already, was the Method Response also set to "text/plain" using the Empty model. I'm not sure if this has an effect, but if the above doesn't work, just add that in.

这篇关于从Amazon API网关终端节点输出纯文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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