Add gateway response template

Prev Next

Available in Classic and VPC

Define and add a mapping template to be returned in the gateway response body.

Request

The following describes the request format for the endpoint. The request format is as follows:

Method URI
POST /products/{product-id}/apis/{api-id}/responses/{response-type}/templates

Request headers

For headers common to API Gateway, see API Gateway common request headers.

Request path parameters

The following describes the parameters.

Field Type Required Description
product-id String Required Product ID that the API belongs to
api-id String Required ID of the API whose mapped template you want to add
response-type String Required Gateway response type

Request syntax

The request syntax is as follows.

{
  "mappingTemplate" : "mappingTemplate",
  "contentType" : "contentType"
}

Request body

The following describes the request body.

Field Type Required Description
mappingTemplate String Required Content of the template to add
  • 1 - 500 characters
contentType String Required Content type
  • Equivalent to the Content-Type header in HTTP
  • 1 - 100 characters
  • <E.g.> application/json, application/xml, text/plain

Request example

The following is a sample request.

curl --location --request POST 'https://apigateway.apigw.ntruss.com/api/v1/products/********o9/apis/cvcohvd2xj/responses/AUTHENTICATION_FAILED/templates' \
--header 'x-ncp-apigw-timestamp: {Timestamp}' \
--header 'x-ncp-iam-access-key: {Access Key}' \
--header 'x-ncp-apigw-signature-v2: {API Gateway Signature}' \
--header 'Content-Type: application/json' \
--data '{
  "mappingTemplate" : "{ \"error\": \"authentication error\" }",
  "contentType" : "application/json"
}'

Response

The following describes the response format.

Response syntax

The response syntax is as follows.

{
  "apiId" : "apiId",
  "responseType" : "responseType",
  "contentType" : "contentType",
  "mappingTemplate" : "mappingTemplate" 
}

Response status codes

For response status codes common to all API Gateway APIs, see API Gateway response status codes.

Response example

The following is a sample response.

{
    "apiId": "cvcohvd2xj",
    "responseType": "AUTHENTICATION_FAILED",
    "contentType": "application/json",
    "mappingTemplate": "{ \"error\": \"authentication error\" }"
}