Tuesday 1 November 2016

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.

P.S.
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.

17 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. I blog frequently and I virtually admire your content. Your article has truly peaked my interest. I am going to bookmark your website and preserve checking for new details about as soon as according to week. site I subscribed on your RSS feed too.

    ReplyDelete
  3. You actually make it seem like it's really easy with your acting, but I think it's something I think I would never understand. I find that too complicated and extremely broad. I look forward to your next message. I'll try to figure it out!

    Business Analytics Course in Bangalore

    ReplyDelete
  4. Really great Post, Thanks for the nice & valuable information. Here I have a suggestion that if your looking for the Best Digital Marketing Course in Gurgaon Then Join the 99 Digital Academy. 99 Digital Academy offers an affordable Digital Marketing Course in Gurgaon. Enroll Today.

    ReplyDelete
  5. This article covers a few techniques to land more web design and web development jobs in Columbus, Ohio. Web designers in Columbus, Ohio can use these tips and techniques to become successful in web design by getting more jobs from web design companies in Columbus. One Off and Ongoing Website Maintenance Services

    ReplyDelete
  6. https://restforchrome.blogspot.com/2016/11/variables-and-environments-in-advanced.html?showComment=1622034771693#c6507893696859390543

    ReplyDelete
  7. Thanks For Sharing the way you presented is really amazing this helped me to gain a knowledge
    Best Software Training Institues

    ReplyDelete
  8. Very useful and knowledgeable. Really its Great Article. Keep it up. A complete APP solution for dokan marketplace for your customer, vendor, and Driver.

    Dokan driver apps

    ReplyDelete
  9. Really, this article is truly one of the best in article history. I am a collector of old "items" and sometimes read new items if I find them interesting. And this one that I found quite fascinating and should be part of my collection. Very good work!

    Digital Marketing Training in Bangalore

    ReplyDelete
  10. Your work is very good and I appreciate you and hopping for some more informative posts
    data scientist certification malaysia

    ReplyDelete