Why to use variables and environments?Lets say you have different environment for your app: development, staging and production. On this three servers you need to pass different - for example - authentication parameters. You can define three environments in the Advanced REST Client (one for reach real environment of your app) and create a variable that will contain a value that needs to be passed to this particular environment. OAuth access token for example. Then you use this variable in the suitable place (URL or headers for example) and during the request this variable will be replaced with proper value.
Consider following examples.
Here, the authToken variable has been defined for the staging environment which is selected right now. We'll use this variable in the URL:
The same will happen if you put a variable anywhere in the headers and payload panels as well.
Variable definitionVariable is always a string. Even if the type can be numeric it's always a string. And it's a good thing actually because you don't need to care about types in the app.
You can define a variable value as a string, concatenation of string and other variables or concatenation of variables.
Consider following example:
And the response:
The theHeader value is a concatenation of both secret and clientId variables and predefined variable now which inserts current time.
There is a limitation, though. You can't use a variable in the other's variable value if this variable has already a concatenation of variables. It will produce an error in the request.
The wontWork variable will produce following output:
It's a safety mechanism to not create circular object dependencies which will create infinite loop and eventually will crash the app because it will run out of memory. Therefore only one level of variables are allowed.
Disabling variablesSingle variable can be disabled by unselecting the checkbox next to it's name.
You can also completely disable variables in the app settings if you don't want the variables to be applied at all.
Future of the variablesRight now you have to assign a value of the variable manually. And also you have to know the value at the moment. Future releases of the Advanced REST Client will have this feature more advanced by adding scripting environment where you'll be able to assign value of the variable depending on the response for selected or any request. It makes authorisation and token exchange flow much easier to manage in the app.
Next step will be to add string and numbers manipulations functions to the variables so if needed you'll be able to - for example - subtract a token value from the response header of calculate a value of the variable depending on other variables.
At the moment when this blog post has been published, version 8 of the app is in beta channel. You can test this and report early feedback. It will be released into the stable channel in coming weeks.