Skip to main content
Feedback

Expression Language response

Updated 

Use Expression Language (EL) in supported API Gateway policy fields to read response properties and evaluate response data.

Access response properties through the #response object. The data available to an expression depends on the policy, its execution phase, and the policies that have already run.

For expression syntax and supported operators, see Expression Language basic usage.

Response object properties

The following table lists the properties available through #response.

PropertyDescriptionTypeExample
statusHTTP response status code.Integer{#response.status}
headersHTTP response headers. A header can contain multiple values.Header collection{#response.headers['Content-Type'][0]}
contentBody content.String{#response.content}

Reading the response status

Use the status property to retrieve the HTTP response status code:

{#response.status}

To check whether the status code is 200:

{#response.status == 200}

To return a value based on a condition:

{#response.status == 200 ? 'OK' : 'Other status'}

Reading response headers

Response headers can contain more than one value. Use bracket notation to retrieve the values for a header name, and an index to select a single value.

Use bracket notation for header names that include a hyphen, such as Content-Type. Dot notation doesn't work with hyphenated names, so {#response.headers.Content-Type} returns an error.

Get all header values

Use bracket notation to retrieve the values associated with a header name:

{#response.headers['X-Custom-Header']}

Get the first header value

Use index [0] to select the first value of a header:

{#response.headers['Content-Type'][0]}

Working with response content

Use #response.content to read the response body.

Evaluate response text

You can use supported string methods to evaluate response content.

For example, check that content contains more than 1,000 characters:

{#response.content.length() > 1000}

Extract a value from JSON

Use #jsonPath to extract data from a JSON response body.

For the following response:

{
"user": {
"id": "12345",
"name": "Alex"
}
}

Use this expression to retrieve the user ID:

{#jsonPath(#response.content, '$.user.id')}

For this payload, the selected value is 12345.

Extract a value from XML

Use #xpath to extract data from an XML response body.

For the following response:

<user>
<id>12345</id>
<name>Alex</name>
</user>

Use this expression to retrieve the user ID as text:

{#xpath(#response.content, '/user/id/text()')}

For this payload, the selected value is 12345.

On this Page