HTTP & REST Variables

HTTP http and REST rest variables are request variables which may be required if the reaction logic depends on the values of specific HTTP properties (such as Authorization header) or REST values.

HTTP Variable

HTTP variable ($http for XML and http for JSON) contains values of the HTTP request.

Field Value
method HTTP method used to execute this request. Contains POST, GET or any other HTTP method name.
relativeURI A part of the URL beyond matched service URL.
queryString Part of the URL after the question mark. Not URL-decoded.
parameters Parsed and URL-decoded URL parameters. If a parameter is found more than once, it will be provided as a separate element under $http/parameters or as an JSON array value in http.parameters
headers HTTP headers. Values enclosed in quotations in the request are provided without quotation in the values. For example, a SOAPAction header "AddUser" will simply be provided as AddUser

 

Note: you do not have to use the full path to a parameter in http.

You can just use the parameter name, e.g. subid. Read Simplified Variables for more info.

Example

Example of XML $http variable content:

   <http>
      <method>POST</method>
      <relativeURI>http</relativeURI>
      <queryString>a=5&amp;b=6</queryString>
      <parameters>
         <parameter name="b">6</parameter>
         <parameter name="a">5</parameter>
      </parameters>
      <headers>
         <header name="SOAPAction">http://domain/Services.ActivityCenter/IActivityService/SubmitActivity</header>
         <header name="Accept-Encoding">gzip,deflate</header>
         <header name="User-Agent">Apache-HttpClient/4.1.1 (java 1.5)</header>
         <header name="Connection">keep-alive</header>
         <header name="Host">localhost:7080</header>
         <header name="Content-Type">text/xml;charset=UTF-8</header>
         <header name="Content-Length">242</header>
      </headers>
   </http>

And a similar content for the JSON http variable:

{
   "headers":    {
      "Host": "localhost:7080",
      "Content-Length": "18",
      "Accept-Encoding": "gzip,deflate",
      "User-Agent": "Apache-HttpClient/4.1.1 (java 1.5)",
      "Connection": "keep-alive",
      "Content-Type": "application/json"
   },
   "relativeURI": "http",
   "queryString": "a=100&b=200",
   "method": "POST",
   "parameters":    {
      "b": "200",
      "a": "100"
   }
}

REST Variable

REST variable ($rest for XML or rest for JSON) is a subset of HTTP values specific to REST protocol. The most important benefit of this is that it allows you to read the values of parameters encoded in the REST URL.

Field Value
method HTTP method used to execute this request. Contains POST, GET or any other HTTP method name.
relativeURI A part of the URL beyond matched service URL.
parameters URL-defined parameters. For example, for an URL such as /accounts/100500, the second fragment (100500) can be defined as a REST variable accountId if the reaction specifies the match by relative URL /accounts/{accountId}

 

Note: you do not have to use the full path to a parameter in rest. You can just use the parameter name, e.g. subid. Read Simplified Variables for more info.

Example

For example, here’s a REST URL: http://localhost:7080/SelfTest/REST/customers/12345. It contains customer ID (12345) as its part. The service URI is /REST, and so the relative URI is /customers/12345.

Provided that a match in the reaction is defined as Relative URL=customers/{customerId}, the value 12345 is assigned to a REST variable customerId, and the REST variable will be:

XML:

   <rest>
      <method>GET</method>
      <relativeURI>customers/12345</relativeURI>
      <parameters>
         <parameter name="customerId">12345</parameter>
      </parameters>
   </rest>

The customerId can then be accessed as $rest//*:parameter[@name='customerId']/text() or just as $customerId.

JSON:

{
      "method": "GET",
      "parameters": {
        "customerId": "12345"
      },
      "relativeURI": "customers/12345"
}

The customerId can be accessed as rest.parameters.customerId or just as customerId.