Request actions
This documentation explain what is and how to use request actions in Advanced REST Client.
Create request actions to dynamically assign variables when the response from the endpoint is ready. ARC gives you a convenient editor to create actions that are performed each time the request is sent.
Actions can be conditional. Create a condition rule for the request action and the action is performed only if all conditions are met.
This page describes in detail how to use request actions and conditions.
Request actions overview
There are two groups of actions that can be performed during the request
  • request actions - executed before the connection is made
  • response actions - executed when the response is ready

Request actions

Currently request action only allows you to set a value on a variable before the request is made. This value is not stored in the data store but rather in memory only. This means when you restart the application the variable value will be restored to its original value.
Request action with definition
In this example, a myAccessToken variable is set to empty string before the request is executed.

Response action

Response actions are more complex as they are made to extract data from the response and assign the value to a variable or store the variable in the data store.
The data can be extracted from each part of the request/response parts of the HTTP message: URL, headers, status line, and the payload.

Extracting the data from the response

You need to tell the application where to look for the data that you want to extract from the response. In the editor, you can select either Request or Response as the main data source. In both cases, the rest of the configuration is the same but it uses either request or response values.
The next step is to define what type of data the application should query for the value. It can be Url, Status code, Headers or Body.
Except for the status code, you should also define the path to the data. Depending on the selected type you can use different paths.

Path to the data

URL
If you do not specify the path the application will use the whole URL of the last response (it can be more than one response if there was redirection). You can specify the following paths for url:
  • host - Returns the host value, e.g. api.domain.com
  • protocol - Returns URL's protocol, e.g. https:
  • path - URL's path, e.g. /path/to/resource.json
  • query - Returns full query string, e.g. version=1&page=test
  • query.[any string] - Returns the value of a query parameter. For query.version it would return 1and for query.page the value will be test.
  • hash - Returns everything that is after the # character, e.g. access_token=token&state=A6RT7W
  • hast.[any string] - It treats hash as query parameters and returns the value of the parameter. For hash.access_token it would return token
Example for URL type
https://auth.domain.com/auth/oauth-popup?version=2&remember=true#access_token=z8a1d97c-c4e6-488f-8ac0-a32e3d749f49&token_type=bearer&state=Y2I1CD
1
path = 'host' // auth.domain.com
2
path = 'protocol' // https:
3
path = 'path' // /auth/oauth-popup
4
path = 'query' // version=2&remember=true
5
path = 'query.version' // 2 (String!)
6
path = 'hash' // access_token=z8a1d97c-c4e6-488f-8ac0-a32e3d749f49&token_type=bearer&state=Y2I1CD
7
path = 'hash.access_token' // z8a1d97c-c4e6-488f-8ac0-a32e3d749f49
Copied!
Headers
Set header name as a path and the value of the header will be extracted from request or response.
Example for headers
1
Content-Type: application/json
2
Content-Length: 100
3
Connection: close
Copied!
1
path = 'content-type' // application/json
2
path = 'Content-length' // 100 (String!)
3
path = 'Connection' // close
Copied!
Body
Currently, only JSON and XML responses are supported. Also, XML has to be a valid XML string or the parser will not produce the value.
For JSON types simply specify the path to the data. To access array value use dot with index notation, for example data.0.name. This will get value name from the first item of the data array.
Example for JSON
1
{
2
property: {
3
otherProperty: {
4
value: 123456
5
}
6
}
7
}
8
path = 'property.otherProperty.value' // 123456
Copied!
Example for JSON array
1
{
2
"data": [{
3
"name": "a"
4
}, {
5
"name": "b"
6
}]
7
}
8
path = 'data.1.name' // b
Copied!
XML
Similar for XML:
1
const xml = `<?xml version="1.0"?>
2
<people xmlns:xul="some.xul">
3
<person db-id="test1">
4
<name first="george" last="bush" />
5
<address street="1600 pennsylvania avenue" city="washington" country="usa"/>
6
<phoneNumber>202-456-1111</phoneNumber>
7
</person>
8
</people>`
9
path = 'people.person.0.phoneNumber' // 202-456-1111
Copied!
Accessing XML attribute value
XML path supports attr(ATTRIBUTE NAME) function that returns the value of the attribute:
1
path = 'people.person.0.name.attr(first)' // george
Copied!

Defining the resulting action

When path is set you can define two actions to be performed on the data. You can either permanently Store variable in the application's internal database or Assign variable temporarily until you restart the application. The last item is to define a variable name that will be updated with the value.
Response action definition

Conditions

You can add a condition to the action so the action will be executed if all defined conditions are met.
To add a condition to the action click on the Add condition button. Source, Type, and Path to data work the same way as in Action editor.
After you define the source of the data choose the operator to be used to compare the data. It can be one of:
  • equal
  • not-equal
  • greater-than
  • greater-than-equal
  • less-than
  • less-than-equal
  • contains
Contains can operate on strings, whole headers object (contains "content-type") and on JSON objects (contains "property").
The last field to set up is Condition value which is used to compare the data.

Further reading