-
Notifications
You must be signed in to change notification settings - Fork 472
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
Variable replacement in file bodies #1116
Comments
It could be indeed useful. But we must be clear whether the content is binary or text. |
I like the idea and started looking into it. I wonder why hurl is not using a mustache based templating system like https://github.com/nickel-org/rust-mustache. |
We haven't looked specifically at this crate. We understand that using an external crate is attractive. But generally, we want to minimize external dependencies and have a good/consistent error reporting within Hurl. For the time-being, it was easier to do with internal code. |
This sounds reasonable. So I would work on this using the existing templating as it is.
{
"foo": "{{bar}}"
} |
I’m not sure we’re ready to develop the feature, I prefer we discuss the potential syntaxes before. For instance, we plan to have support for « generator » in template:
To create a body with current time. This kind of generator could be used for providing a templatized body :
You can work on it, but not I’m not convinced by |
Looking at the generator feature, this is basically what the mustache crate brings on the table by allowing closures to be bound to the template context. Which is the reason I was asking this in the first place. If hurl would parse the inline body using the mustache template crate, the generator feature would be a matter of adding closures like template or at least this would be a start. |
Discussed in #2713
|
Problem to solve
I prefer to set the request body from a file to keep IDE's syntax support applicable to the given file type
Unfortunately, the
{{variable}}
replacement tokens do not work thereProposal
Given that some file types may use the double brace for its own purposes, I'd suggest a new option which would opt-in to replace
{{foobar}}
as it would when the body was inline in a.hurl
fileRequest file:
body.json
:When called like
hurl --variable bar=baz
, it should replace the{{bar}}
token in the JSON file before sending the request.Might also consider a CLI switch
--replace-file-variables
The text was updated successfully, but these errors were encountered: