Vscode-restclient: Use variables inside http/rest files

Created on 26 Jul 2016  ยท  22Comments  ยท  Source: Huachao/vscode-restclient

  • VSCode Version: 1.3.1
  • OS Version: Windows 10.10586
  • REST Client Version: 0.6.1

Requirements:

The goal is to be able to make flexible REST client file. Adding variables, it could be simple to do those sort of things :

  • Base url
  • Reuse previous response
  • Use token (https://github.com/Huachao/vscode-restclient/issues/22#issuecomment-235603249)

Tasks:

  • [x] environment variable (you can define prod/sandbox/... variables)
  • [x] global dynamic variables (I will provide function like {{$guid}}, then you can use this in your request when you needs a new guid) support in the future.
enhancement

Most helpful comment

@Odonno @shytikov @jd987 @dcbrwn I have implemented the feature of custom variables and environment, and will publish the new version ASAP, and at that time, you could have a try and give me suggestions and feedback. Thank you all ๐Ÿ˜„

All 22 comments

@Odonno , nice suggestion, however I think my goal now is a stand alone http client tool/extension, this feature can be implemented in you js code by referencing a javascript http client library.

I think it would be just enough to be able build chains of requests in one input window.

  1. You've requested a token;
  2. You're using that token to request information about something;
  3. Or use output of that request to feed it as input for next request.

If some kind of simple syntax could be developed, like:

  1. Automatically assign id to request;
  2. Expose response for that request JS object linked to request id;
  3. Use fields of that response in further requests.

@shytikov @Odonno , your suggestions are really great, thanks so much. I will consider how to implement it carefully, and update in this thread later.

@Huachao Yes, we can do that using a js library, now I see that. I just bring that question with potential usages but @shytikov seems to have one major needs, in case the response is highly variable (token example).

Now, I think that introducing a script language is too much. Maybe global variables like @id that you can replace in the entire page could be just enough, I suppose.

What do you think ?

@Odonno Yes, I totally agree, I'd like to add

  • environment variable(you can define prod/sandbox/... variables)
  • global variables(cross environment)
  • system dynamic variables(I will provide function like {{$guid}}, then you can use this in your request when you needs a new guid) support in the future.

Thanks @Huachao and @shytikov , I updated my first comment.

@Odonno @shytikov global system dynamic variables {{$guid}} and {{$timestamp}} have been supported in latest version 0.8.0, you can have a try and environment variables will be supported later.

Ability to set variable to result of HTTP request will be very helpful.

@dcbrwn what do you mean the result of HTTP request, can you give me some samples, sorry

For example I want to reuse auth. token in multiple requests. Like this maybe:

$authToken =
GET http://localhost/api/auth/token
Content-Type: application/json

{
  "login": "some",
  "password": "asdfasdfasdf",
}

GET http://localhost/api/clients
Authorization: $authToken

GET http://localhost/api/products
Authorization: $authToken

Some links for inspiration:
https://github.com/pashky/restclient.el
https://www.youtube.com/watch?v=fTvQTMOGJaw

Basically my intention is exactly the same as @shytikov's.

@dcbrwn to make it work as restclient.el, I think we can achieve the same goal in a simpler way to implement, after we enabled add user's custom variables ๐Ÿ˜„

When can we expect to see the user custom variable feature?

@jd987 I am a little busy recently, and haven't considered it carefully will fix this later. If you wish, you could help to contribute to the environment and variable feature, that will be a big welcome. Sorry for the inconvenience.

Sorry but that is outside my area of expertise. I am eager to see this and context menu support. Wonderful plugin

@jd987 I will implement the environment variables feature ASAP, and context menu support already published in version 0.11.4

@Odonno @shytikov @jd987 @dcbrwn I have implemented the feature of custom variables and environment, and will publish the new version ASAP, and at that time, you could have a try and give me suggestions and feedback. Thank you all ๐Ÿ˜„

@Huachao Thank you for the work done! I'll give a try as soon as I can.

Can't wait!

On Tue, Jan 10, 2017 at 2:06 AM, David Bottiau notifications@github.com
wrote:

@Huachao https://github.com/Huachao Thank you for the work done! I'll
give a try as soon as I can.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Huachao/vscode-restclient/issues/22#issuecomment-271510942,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC0lH5RKxIuI_N3FcBRRmr3_brd0Vvcoks5rQzv3gaJpZM4JVnyI
.

--
JD

@Odonno @shytikov @jd987 @dcbrwn now you can try the custom environment and variable feature in latest version 0.12.0, thanks for your feedback and suggestion ๐Ÿ˜„

Oops - my mistake, I was doing it wrong - I've edited this comment rather than just deleting...

I thought this wasn't working

// $test: getSomeData
// $startDate: 1/6/2017
// $endDate: 1/6/2017

GET http://www.foobar.com/api/foo/{{ $test }}
    ?startDate={{ $startDate }}
    &endDate={{ $endDate }}

The problem is that I was doing it wrong. Based on what I read in comments I was trying to create variables in my test.http file, rather than in the settings and creating variables in the environment scope. Once the variables are created there, they work as expected.

However, I'd love to be able to create variables in my test.http file if that's ever a possibility.

Thanks for the great tool!

@seanwcom this is a really interesting idea to define file scope variable, I will consider it in future release, thanks so much for your usage and suggestion. And one more thing, my preferred way to name a variable starts without $ sign, since I meant to preserve all the variables start with $ are global system variables, they will be replaced before custom variables, so if your variables conflict with global ones, global ones' value will be used

Here is the complete tutorial for rest client - https://www.youtube.com/watch?v=Jf4SFY1yT1k

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnbeynon picture johnbeynon  ยท  23Comments

OzgurDogan picture OzgurDogan  ยท  13Comments

heneds picture heneds  ยท  32Comments

lldata picture lldata  ยท  13Comments

abenedykt picture abenedykt  ยท  18Comments