Extract REST request attributes

Overview

This filter extracts the values of query string parameters and/or HTTP headers from a REST request and stores them in separate message attributes. The request can be an HTTP GET or HTTP POST request. This filter is in the Attributes category in Policy Studio. For details on creating a REST request, see Create REST request.

HTTP GET requests

The following example shows an incoming HTTP GET request with query string and HTTP headers:

GET /services?name=Niall&location=Dublin&location=Pembroke%20St HTTP/1.1
Host: mail.google.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.15) 
Gecko/20110303 Firefox/3.6.15
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Using this example, the Extract REST Request Attributes filter generates the following attributes:

http.header.Host = mail.google.com
http.header.User-Agent = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.15) 
Gecko/20110303 Firefox/3.6.15
http.header.Accept = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
http.header.Accept-Language = en-gb,en;q=0.5
http.header.Accept-Encoding = gzip,deflate
http.header.Accept-Charset = ISO-8859-1,utf-8;q=0.7,*;q=0.7

http.querystring.name = Niall
http.querystring.location.1 = Dublin
http.querystring.location.2 = Pembroke St

This filter extracts all parameters from an incoming REST request, and stores them in separate message attributes so that they can be validated easily, without needing to iterate through the set of http.headers.

[Note] Note
For multi-valued query string parameters (for example, location), each value is given an incremental index. For example, the multi-valued location parameter results in the creation of the http.querystring.location.1 and http.querystring.location.2 message attributes.

HTTP POST requests

When you POST a form to the API Gateway, the parameters are placed in the message body, and not in the query string. However, the Extract REST Request Attributes filter treats posted parameters the same as normal query parameters, and also adds them to the http.querystring message attribute in a similar way to the HTTP GET request. For example, an HTTP POST message body contains the following:

grant_type=test&test1=a&test2=b

This means that the ${http.querystring.grant_type} message attribute selector will contain a value of test.

Configuration

Configure the following fields on the Extract REST Request Attributes screen:

Name:

Enter an appropriate name for this filter.

Request Querystring:

Select whether to extract the values of query string parameters from an HTTP POST or GET request. These are simple name-value pairs (for example, Name=Joe Bloggs). This setting is selected by default.

HTTP Headers:

Select whether to extract the HTTP header values from an HTTP POST or GET request (selected by default).

Decode Extracted Attributes:

Select whether to decode URI paths that have been percent-encoded (for example, using %2F for /). This setting enables compatibility with previous API Gateway versions, which decoded URI paths, and is not selected by default. For example, this means that URI path components such as the following stay in a raw state:

/s8koID4%2FAd6AqgADSghC%2Bg%3D%3D/book%20repo/first%20book.pdf

This results in:

path[0] = ""
path[1] = "s8koID4%2FAd6AqgADSghC%2Bg%3D%3D"
path[2] = "book%20repo"
path[3] = "first%20book.pdf"

When this setting is selected, the URI path is decoded. This results in:

path[0] = ""
path[1] = "s8koID4%/Ad6AqgADSghC+g=="
path[2] = "book repo"
path[3] = "first book.pdf"