# How are 'template' and 'pattern' used for response definitions?

**URL:** <https://forum.serverless.com/t/how-are-template-and-pattern-used-for-response-definitions/11938>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, api-gateway\
**Created:** [July 6, 2020, 12:18pm UTC](https://forum.serverless.com/t/how-are-template-and-pattern-used-for-response-definitions/11938 "2020-07-06T12:18:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbarrington42](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bbarrington42/32/7431_2.png) [@bbarrington42](https://forum.serverless.com/u/bbarrington42)\
**Post date:** [July 6, 2020, 12:18pm UTC](https://forum.serverless.com/t/how-are-template-and-pattern-used-for-response-definitions/11938/1 "2020-07-06T12:18:49Z")

</div>

Hello,  
I need more information regarding how to use the ‘template’ & ‘pattern’ keys when defining a REST API. The example that I see in the docs is below. However, I can’t find any documentation about how to define the values for these keys. I assume it is there somewhere, but so far I’ve come up short.  
Thanks.

```
functions:
  create:
    handler: posts.create
    events:
      - http:
          method: post
          path: whatever
          integration: lambda
          response:
            headers:
              Content-Type: "'text/html'"
            template: $input.path('$')
            statusCodes:
              201:
                pattern: '' # Default response method
              409:
                pattern: '.*"statusCode":409,.*' # JSON response
                template: $input.path("$.errorMessage") # JSON return object
                headers:
                  Content-Type: "'application/json+hal'"
```

---

<div class="post-metadata">

**Author:** ![bbarrington42](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bbarrington42/32/7431_2.png) [@bbarrington42](https://forum.serverless.com/u/bbarrington42)\
**Post date:** [July 6, 2020, 2:42pm UTC](https://forum.serverless.com/t/how-are-template-and-pattern-used-for-response-definitions/11938/2 "2020-07-06T14:42:05Z")

</div>

NM. After lots of digging, I determined that what I was trying to do required an entry in the ‘resources’ section of the template.yml file (shown below). Lots of digging required. Very slow going…

```
 badRequestBodyResponse:
      Type: AWS::ApiGateway::GatewayResponse
      Properties:
        ResponseTemplates:
          application/json : "{\n \"message\": $context.error.validationErrorString,\n \"type\": \"$context.error.responseType\",\n \"stage\": \"$context.stage\",\n \"resourcePath\": \"$context.resourcePath\",\n \"stageVariables.a\": \"$stageVariables.a\",\n \"statusCode\": \"'400'\"\n}"
        ResponseType: 'BAD_REQUEST_BODY'
        RestApiId: !Ref ApiGatewayRestApi
        StatusCode: '400'
```
