vscode-restclient
vscode-restclient copied to clipboard
Overwrite environment variable with value of request variable
- VSCode Version: 1.21.1
- OS Version: Win10
- REST Client Version: 0.18
After publishing the feature related to #140 I was expecting that the request in #86 was also going to be picked up. My request is much more generic than described in #86.
I would like to have the possibility to overwrite an environment variable from a value of an request variable.
So the following code would end up with updated value in my environment variable
# @name session
POST {{domain}}/v1/sessions HTTP/1.1
content-type: application/json
accept: application/json
{
"userId": "{{userId}}",
"password": "{{password}}"
}
{{token}} = {{session.response.body.token}}
In my example {{domain}} is a "workspace" setting, so it is shared within my team. {{userId}}, {{password}} and {{token}} are stored as user settings, so it is related to my account.
And by updating {{token}} I don't need to add this session request to all files and execute them one by one per file
@OzgurDogan I'd like to consider this carefully, and think about the design carefully. And I will update in this thread later. Thanks for your suggstion
@OzgurDogan in latest version 0.20.2, you can set the file variable value with references of request variables, like @token = {{session.response.body.token}}
. Does this solve your problem?
@Huachao unfortunately what I would like to achieve is to store te value in a setting file so it can be shared over files.
@Huachao currently is there anyway to preview current assigned value from response body? it would nice to have a preview of current value. (in form of codelens or something)
@jahan01 you can hover over the request variable references like {{session.response.body.token}}
Having the ability to overwrite an environmental variable is very important to me as well. I have dozens of requests and do not want to put my username/password in a post request in every file. I really need to have only one single file that has this authentication request and all the other files will read the environmental value that was set. Thanks for this awesome tool so far though!
This is a very important feature. And it's absence is the reason why I'm still using Postman.
The feature that is close to this one and already implemented in postman is : postman.setGlobalVariable("key", value);
Same here @Croverit . This feature would be a huge win for this project IMO.
Is this proposed option is planned to implement in the future? What are the barriers to overcome?
I too am wanting to move from Postman to this extension, but the "environment" and "globals" variable issue, is something that would be decisive for me.
I have flows and within each request, I extract a different reference and then use this to call the next request.
Not being able to do this using REST API would prevent me from making the plunge and going all in, leaving Postman behind.
Hi, I think this is what I need too. I want to set up a project with different workspaces linked all together by a settings.json but I want to be able to add/override certain variables only at workspace level (different client/different workspace, each one with a different name variable, etc). Can this be linked to: https://github.com/Huachao/vscode-restclient/issues/251 ? Great tool. Thanks.
I created a powershell script that I can quickly call in the vscode terminal to have my token environment variable updated for now. Its working very well for me, and much better than copying it every time manually.
$env=$args[0]
$json = Get-Content '.vscode/settings.json' -raw | ConvertFrom-Json
$settings = $json.{rest-client.environmentVariables}
if($env -eq 'local'){
$postParams = @{
username = $settings.{local}.{userName};
password = $settings.{local}.{password};
}
$uri = (-join($settings.{local}.{host}, 'post'))
$response = Invoke-WebRequest -Uri $uri -Method POST -Body $postParams
$token = $response | ConvertFrom-Json | Select-Object access_token
#Write-Host $token.psobject.properties.value
$settings.{local}.{token} = $token.psobject.properties.value
}
elseif($env -eq 'prod'){
# todo: add request
}
else {
write-host("Environment undefined. Please try again.")
}
$json | ConvertTo-Json | set-content '.vscode/settings.json'
This extension is pretty great, but this feature is an essential one for many people workflows.
One way could be to allow us to rewrite an environment variable with a different syntax, like
@@environment_variable = "something"
to make it crystal clear we are not changing a file variable.
This could actually modify the vscode config file, or just be a temporary state until vscode restart (even better).
Two years have passed since this issue was open, are there any news? It makes this extension a missed replacement of postman for me (and many others as it appears)
I've just moved from postman to rest-client, but got disappointed when I found out that there is no way to change environment variables, this issue was open for 3 years, and yet not implemented
I was going to use rest-client, but without this feature it becomes unusable 😢
Joining on board here, rooting for this feature to be implemented !
how come this has not been added yet? this is completly essential to the whole client being actually useable, just sharing an auth token across the different files is literally impossible
Any chance for add it? request variables would be great if only sharable via many files.
Hey, how's everyone going? It's been another year since the last comment. Do we have any news? This feature would be really awesome