DVA-C02 · Question #387
A company has a serverless application that uses Amazon API Gateway backed by AWS Lambda proxy integration. The company is developing several backend APIs. The company needs a landing page to provide
The correct answer is C. Configure the integration request mapping template with Content-Type of application/json and. For an API Gateway mock integration to return an HTML landing page, the integration response must map the mock response body to HTML content with the correct Content-Type header, using a mapping template of type application/json for the request and text/html for the response.
Question
A company has a serverless application that uses Amazon API Gateway backed by AWS Lambda proxy integration. The company is developing several backend APIs. The company needs a landing page to provide an overview of navigation to the APIs. A developer creates a new/LandingPage resource and a new GET method that uses mock integration. What should the developer do next to meet these requirements?
Options
- AConfigure the integration request mapping template with Content-Type of text/html and
- BConfigure the integration request mapping template with Content-Type of application/json. In the
- CConfigure the integration request mapping template with Content-Type of application/json and
- DConfigure the integration request mapping template with Content-Type of text/html. In the
How the community answered
(27 responses)- A4% (1)
- B4% (1)
- C85% (23)
- D7% (2)
Why each option
For an API Gateway mock integration to return an HTML landing page, the integration response must map the mock response body to HTML content with the correct Content-Type header, using a mapping template of type application/json for the request and text/html for the response.
Setting the integration request Content-Type to text/html is incorrect; the mock integration request must use application/json because the mock endpoint communicates in JSON internally.
Configuring only the integration request with application/json without properly setting the response mapping and Content-Type for the HTML output will not produce a renderable HTML page for the client.
In a mock integration, the integration request mapping template uses Content-Type application/json to define the static JSON payload returned by the mock, and the integration response mapping template transforms that payload and sets the Content-Type to application/json in the request body while the method response header returns text/html, enabling the browser to render the HTML landing page correctly.
Setting the integration request Content-Type to text/html is not valid for mock integrations, which require application/json in the request mapping template to define the statusCode and body for the mock response.
Concept tested: API Gateway mock integration response mapping for HTML
Source: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-mock-integration.html
Community Discussion
No community discussion yet for this question.