Using Models - AWS Serverless API

Method Request - Section

 A Model can be used as a request body. And we can validate it by setting "Request Validator" = "Validate Body". This will stop continuing request if the body does not match with the validation model.

Integration Request - Section

 Here we can use a Model as Body Mapping Template. In some situations we do not need to pass all data from request to back end (Lambda function). Then we can use mapping templates to pass specific data to the back end.

Example:
This is our request validation model
{
  "name" :"Suresh"
  "salary" : "32"
}

When only "salary" is need to pass to lambda function the mapping template may be:
#set($inputRoot = $input.path('$'))
{
  "salary" : $inputRoot.salary
}

Integration Response - Section

 Here we can use a Model as Body Mapping Template. In some situations we do not need to pass all data from back end to response. Or we need to change some names to user readable names.

Method Response - Section

Here we can use models for response body too.

Comments

Popular posts from this blog

DynamoDB - AWS Serverless API