API Gateway Model and Mapping template

API Gateway Mapping Template 

  • Model: You would define the model in the method request configuration of your API Gateway resource. This model would specify the structure and validation rules for the incoming request payload.

  • Mapping Template: You would create a mapping template in the integration request configuration of your API Gateway resource. This template would transform the incoming JSON payload into XML format before passing it to the backend service.


Sure! Here's an example demonstrating how to define a model and use a mapping template in AWS API Gateway:

1. Define Model:

Suppose we want to define a model for a Feedback object with properties name, email, rating, and comments. We'll define this model using JSON Schema.

json
{ "type": "object", 
"properties":
{ "name": { "type": "string" }, 
"email": { "type": "string", "format": "email" }, 
"rating": { "type": "integer", "minimum": 1, "maximum": 5 }, 
"comments": { "type": "string" } }, 
"required": ["name", "email", "rating", "comments"] }

2. Use Mapping Template:

Suppose we want to transform incoming JSON requests into XML format expected by the backend service. We'll create a mapping template using Velocity Template Language (VTL).

velocity
#set($inputRoot = $input.path('$')) 
{ "Feedback": { "Name": "$inputRoot.name", 
 "Email": "$inputRoot.email",
 "Rating": $inputRoot.rating, 
 "Comments": "$inputRoot.comments" } }

Comments

Popular posts from this blog

Read and Navigate XML - Beautiful Soup

difference-between-stream-processing-and-message-processing

WordNet in Python