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
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
myAccessTokenvariable is set to empty string before the request is executed.
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.
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
Responseas 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
Except for the status code, you should also define the path to the data. Depending on the selected type you can use different paths.
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
- host - Returns the host value, e.g.
protocol- Returns URL's protocol, e.g.
path- URL's path, e.g.
query- Returns full query string, e.g.
query.[any string]- Returns the value of a query parameter. For
query.versionit would return
query.pagethe value will be
hash- Returns everything that is after the
hast.[any string]- It treats hash as query parameters and returns the value of the parameter. For
hash.access_tokenit would return
Example for URL type
path = 'host' // auth.domain.com
path = 'protocol' // https:
path = 'path' // /auth/oauth-popup
path = 'query' // version=2&remember=true
path = 'query.version' // 2 (String!)
path = 'hash' // access_token=z8a1d97c-c4e6-488f-8ac0-a32e3d749f49&token_type=bearer&state=Y2I1CD
path = 'hash.access_token' // z8a1d97c-c4e6-488f-8ac0-a32e3d749f49
Set header name as a path and the value of the header will be extracted from request or response.
Example for headers
path = 'content-type' // application/json
path = 'Content-length' // 100 (String!)
path = 'Connection' // close
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
namefrom the first item of the
Example for JSON
path = 'property.otherProperty.value' // 123456
Example for JSON array
path = 'data.1.name' // b
Similar for XML:
const xml = `<?xml version="1.0"?>
<name first="george" last="bush" />
<address street="1600 pennsylvania avenue" city="washington" country="usa"/>
path = 'people.person.0.phoneNumber' // 202-456-1111
Accessing XML attribute value
XML path supports attr(ATTRIBUTE NAME) function that returns the value of the attribute:
path = 'people.person.0.name.attr(first)' // george
pathis set you can define two actions to be performed on the data. You can either permanently
Store variablein the application's internal database or
Assign variabletemporarily until you restart the application. The last item is to define a variable name that will be updated with the value.
Response action definition
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 conditionbutton. 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:
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 valuewhich is used to compare the data.