Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use variables inside http/rest files #22

Closed
2 tasks done
Odonno opened this issue Jul 26, 2016 · 22 comments
Closed
2 tasks done

Use variables inside http/rest files #22

Odonno opened this issue Jul 26, 2016 · 22 comments

Comments

@Odonno
Copy link

Odonno commented Jul 26, 2016

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

Tasks:

  • environment variable (you can define prod/sandbox/... variables)
  • 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.
@Huachao
Copy link
Owner

Huachao commented Jul 26, 2016

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

@shytikov
Copy link

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.

@Huachao
Copy link
Owner

Huachao commented Jul 27, 2016

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

@Odonno
Copy link
Author

Odonno commented Jul 27, 2016

@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 ?

@Huachao
Copy link
Owner

Huachao commented Jul 27, 2016

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

@Odonno Odonno changed the title Add script language inside *.http/*.rest files Use variables inside http/rest files Jul 27, 2016
@Odonno
Copy link
Author

Odonno commented Jul 27, 2016

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

@Huachao
Copy link
Owner

Huachao commented Sep 20, 2016

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

@ghost
Copy link

ghost commented Oct 11, 2016

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

@Huachao
Copy link
Owner

Huachao commented Oct 11, 2016

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

@ghost
Copy link

ghost commented Oct 11, 2016

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.

@Huachao
Copy link
Owner

Huachao commented Oct 11, 2016

@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 😄

@jd987
Copy link

jd987 commented Jan 3, 2017

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

@Huachao
Copy link
Owner

Huachao commented Jan 3, 2017

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

@jd987
Copy link

jd987 commented Jan 4, 2017

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

@Huachao
Copy link
Owner

Huachao commented Jan 4, 2017

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

@Huachao
Copy link
Owner

Huachao commented Jan 10, 2017

@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 Huachao closed this as completed Jan 10, 2017
@Odonno
Copy link
Author

Odonno commented Jan 10, 2017

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

@jd987
Copy link

jd987 commented Jan 10, 2017 via email

@Huachao
Copy link
Owner

Huachao commented Jan 15, 2017

@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 😄

@seanwcom
Copy link

seanwcom commented Jan 17, 2017

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!

@Huachao Huachao reopened this Jan 17, 2017
@Huachao Huachao closed this as completed Jan 17, 2017
@Huachao
Copy link
Owner

Huachao commented Jan 17, 2017

@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

@kalanchiyamtutorial
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants