英文:
How to return the request body back to client after executing API Gateway
问题
我有一个简单的API网关客户端,我想做的就是将最初由客户端发送到API的请求主体包含在返回给客户端的响应中。这只是为了确认API接收到了预期的请求主体。
我尝试使用以下映射模板,但它们返回空值:
{
"requestBody": $method.request.body // 也尝试过在值周围加上引号
}
{
"requestBody": "integration.request.body"
}
这是一个SQS集成,然而,我只想要发送到API本身的请求主体,与sqs接收到的内容无关。
英文:
I have a simple API-Gateway client and all I want to do is include the request body, initially sent by client when hitting the api, back to the client. This is just to confirm that the api received the expected request body.
I tried using the following mapping templates, but they return empty:
{
"requestBody": $method.request.body // also tried this with the quotes around the value
}
{
"requestBody": "integration.request.body"
}
This is an SQS integration, however, I just want the request body sent to the api itself independent of what sqs received.
答案1
得分: 1
添加这个到您的集成响应映射模板中应该可以解决问题:
{
"body-json": $input.json('$')
}
另外,如果您想要查看更多内容,可以在映射模板上方查找生成模板下拉菜单,并选择Method Request passthrough以生成一个映射模板,将所有传入的数据(包括正文、查询字符串等)返回给客户端。
英文:
Adding this to your Integration Response mapping template should do the trick:
{
"body-json" : $input.json('$')
}
Also, if you want to see even more, look for the Generate template dropdown just above the mapping template and select Method Request passthrough to generate a mapping template that returns all passed in data (body, query strings, etc) back to the client.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论