Variables
Using Variables
To use variables use double curly brackets {{ }}
.
{{ id }}
will be replaced with whatever is contained in the variableid
.
User Input
Variables are sourced from a variable set. If a variable doesn't exist in the variable set, user is explicitly prompted to enter the value for that variable.
In case the variable id
doesn't exist in the variable set, user gets a prompt to enter the value.
Variables can be used in path
, headers
, body
.
http.yaml | |
---|---|
- Using variables in path.
- Using variable in headers.
- Using variables in body.
This is perfect for the cases when each time you execute a request you want to provide values at runtime.
Once the value of variable has been sourced from a user, it is added to the variable set.
In the below example,
http.yaml | |
---|---|
User will only be prompted for id
once when yurl
encounters the path /todos/{{ id }}
, once the value is entered it is saved in the variable set and reused in body.
Command Line Variables
You can pass value for variables directly from command line using -var
or --variable
flag.
http.yaml | |
---|---|
You can pass as many variables as you want.
All the variables are added to the variable set.
Variables from a file
You can define variables in a file and pass all of them at once using -var-file
or --variable-file
.
Variables in the file need to follow the pattern: key=value
.
http.yaml | |
---|---|
You can provide as many variable files as you want.
All the variables are added to the variable set.
Variable Types
You can define types on variables when the value is prompted from the user.
Use the pattern: {{ <var name>:<type> }}
to enforce a type.
http.requests | |
---|---|
- Types are defined using
<var name>:<type>
pattern.
In the above example, type int
is defined for the variable id
. When user is prompted for the value of id
the required type is also displayed.
If the entered value is not valid, yurl
exists immediately.
Supported Types
Currently the following types are supported:
string
int
float
bool