Introduce AWS API Gateway Data Mapping Template
By default AWS API Gateway will print out headers in root path, the sample code would be something like this:
{
"statusCode": 200,
"body": "{\"message\":\"Welcome!\"}",
"headers": {
"x-powered-by": "Express",
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"content-length": "22",
"date": "Tue, 03 Mar 2020 05:53:59 GMT",
"connection": "close"
},
"isBase64Encoded": false
}
But we actually just need body part instead of everything. Using {proxy+} could be a solution for the resource in the subdirectory eg “/videos”, but it won’t root directory “/”.
AWS API Gateway Data Mapping
AWS provide API Gateway Data Mapping template for setupping customized response content. It could be used for the solution to address this problem.
So in order to display the body
of the above response, we could use following content in the Mapping Templates settings.
Mapping Template does more than just displaying the body, it could be more powerful that help you to build the desired data model map.
Please check references below for more information regarding AWS Data Mapping Template:
- https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html
- https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference
- https://sookocheff.com/post/api/understanding-api-gateway-payload-mappings/