Variables and environments in the Advanced REST Client

New release of version 8 brings new feature to the app. It's a variables and environments editor. It is an extension to already existing "magic variables" feature introduced in 2012. Earlier you could set a limited number of keywords to generate numbers in any part of the request. Now own variables can be defined  in the app and assigned to environment. During the request the value of the variables will be applied in place where the variable was used.

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:

In the response panel, in the request headers you'll see that the request was altered by the app before sending it to the server:

The same will happen if you put a variable anywhere in the headers and payload panels as well.

Variable definition

Variable 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:

Request headers:

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 variables

Single 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 variables

Right 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.