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

Support persistent mutable environment to support cross file chaining #1977

Open
1 task
95th opened this issue Sep 29, 2023 · 2 comments
Open
1 task

Support persistent mutable environment to support cross file chaining #1977

95th opened this issue Sep 29, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@95th
Copy link

95th commented Sep 29, 2023

Problem to solve

Let's say you have a login.hurl which logins the user and captures the token in a variable. I would like to use this variable with any number of requests after that, possibly in multiple sessions.

Postman supports this using "tests" which is just javascript code where you can modify the environment.

Proposal

Support saving and loading variables to an environment file.

Support a new type of variable:

POST https://foo.com/login
...

HTTP 200
[Captures]
env:token = jsonpath "$.token"

For example:
Below command would load all the env variables from env.json at the beginning and save token to env.json at the end.

hurl --env=env.json login.hurl 

A different hurl file could use this env like so:

hurl --env=env.json requests.hurl 

requests.hurl

GET https://foo.com/api/things
Authorizaton: Bearer {{env:token}}

Additional context and resources

Tasks to complete

  • ...
@95th 95th added the enhancement New feature or request label Sep 29, 2023
@fabricereix
Copy link
Collaborator

Hi @95th ,
Reading variables from a file is supported with the variable-file option.

Relating to writing variables to a file at the end of the test:

  • it can be done currently from the JSON output with an additional command line using jq.
  • we could maybe add a dedicated option for that. This seems very similar to reading/writing cookies to a file. Note that the curl/Hurl are not very intuitive (--cookie, ---cookie-jar)

@yjlcoder
Copy link

Note that the detailed steps to achieve this is explained in this comment: #1208 (comment)

I really wish there's a dedicated option, or a cleaner way to do this. Thanks. Appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants