Comments (9)
To set variables, you can simply add them inline right before the request (see https://httpyac.github.io/guide/variables.html#inline-variables).
@foo=bar
GET https://httpbin.org/anything?q={{foo}}
Or alternatively you could import an .env file, Intellij Idea format or variables from a central http file. It would also be possible to fill them dynamically.
I have not yet planned to change the cached variables. These can be not only text, but also any file types or even special classes (e.g. Date or HMAC). This makes it more complicated and I don't see the benefit so strongly, because there are enough alternatives.
from vscode-httpyac.
The alternative to import env/http files I'm already using but when I set some variable using a script after some response, I can't change the current value again just changing the imported file. Even so, I can go with your first solution.
Nevertheless, if we could change the variable inside the extension's Variables
section could be a nice/simple way to improve user experience, at least for primitive variable types.
from vscode-httpyac.
@klutzer How would you solve the data problem here? I could then only allow the input of text, since VSCode otherwise does not provide me with any controls see https://code.visualstudio.com/api/references/vscode-api#InputBox). Alternatively, only JSON would work, but this would complicate the input of simple text.
from vscode-httpyac.
I don't know if this is a viable option, but maybe we can able user to put some arbitrary JS code and set the variable the same way you do in @myVariable = {{ some JS here }}
from vscode-httpyac.
Another thing I've noticed, is that if I change some environment variable (first defined in .env
) in one .http
file, the new value isn't applied for other files using the same variable. Shouldn't environment values be global scoped by default? Or the only way to reflect a variable change in all files is using $global
?
from vscode-httpyac.
@klutzer The behavior could be a bug. I have a certain order for loading the variables (default > config (file or vscode) > env > cached variables > variables) and it can happen that the variable from the environment is overwritten afterwards. The object displayed as variables in VSCode is not used directly at all, but is only the result of the last execution. I try to separate the variables pots (environement or variable of httpregion). Your description indicates an error in the separation and an example of the error would be interesting.
This is also the reason why manual changing from the outside is also complicated to implement. To determine to which pot the variable belongs is not trivial but necessary that this overwrites the variable at the next execution.
from vscode-httpyac.
Yep, changing variables from the UI isn't so trivial indeed.
An example of the environment variable behavior:
.env:
host = http://httpbin.org
source = envFile
file1.http:
### first
POST /anything
{
"source": "{{source}}"
}
@source = file1
?? body json.source == envFile
### second
POST /anything
{
"source": "{{source}}"
}
?? body json.source == file1
file2.http
### third
POST /anything
{
"source": "{{source}}"
}
?? body json.source == file1
To simulate just execute the requests in order (first, second..). In my understanding, the third
should pass instead of fail.
from vscode-httpyac.
@klutzer I do not have global variables. The environment is global. The variables are always present only in the respective httpRegion. Since this approach was too strict for myself, the variables are leaking in the same file (useRegionScopedVariables = false). To access variables from other files, this file must be imported, and if necessary also the respective HttpRegion.
To override the source variable, I now need to determine that it was created in file1.http - first.
The whole approach is driven by test execution. My goal was that the execution is reproducible and automatable. Your requirement is important during the development of the request that you can easily change the call. In this case I simply adjust the request body directly or try to avoid variables and use multiple requests. I want to focus on the development of the backend and miinimize the cognitive load for tooling.
from vscode-httpyac.
In this case, knowing that environment is global, when I change the env (setting new value to env source
), the new value shouldn't be reflected globally?
For variables (defined in .http
files), you're using a nice approach indeed. The only thing here is, even importing the same variable file in file1
and file2
, file2
will still receive the same value, without the change made in first
request, so we have the same behavior of using envs.
I know this can be undesired, I'm just raising some possibilities to have envs similar to extensions like ThunderClient, where we have global envs as default, and an initial
and current
values for each.
from vscode-httpyac.
Related Issues (20)
- Trigger reset environment (before a test suite) HOT 3
- Markdown response not updated when request repeated with a different body HOT 3
- VSCode: The requested URL could not be retrieved HOT 4
- TestResults always empty HOT 1
- Runner-like function to run load tests in VS Code extension? HOT 5
- [BUG] Broken environment loading HOT 2
- httpRegion.httpFile.activeEnvironment does not exist HOT 1
- Syntax highlight missing for next line of a commentted query item line HOT 1
- How about adding some shortcut keys like jupyter notebook ? HOT 1
- [feature] import curl HOT 2
- OAuth2 / OpenID Connect - Error HOT 3
- setup response path/ clear up response files HOT 4
- Wrong request host HOT 3
- request timeout in vscode but works in cli HOT 3
- Escaping curly braces is not correctly interpreted HOT 3
- env from http-client.private.env.json overwritten with values from template-http-client.private.env.json HOT 1
- JSON key that has spaces un-referencable when using variable injection HOT 3
- Input unexpected behavior HOT 2
- Feature Request: Token Exchange Grant Support for a particular audience in the same realm HOT 2
- Nodejs parsing for query params HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-httpyac.