Variables
#
VariablesVariables can be defined in an HTTP file using the syntax: var name = "some value"
. Once defined, they can be reused throughout the file.
#
Supported Data TypesMath Expressions:
Syntax:var var2 = (2 + 3 + var1);
- Parentheses are mandatory.
String Interpolations:
Syntax:var var3 = $'ranga {var2}';
- The
$
symbol is mandatory.
- The
JSON Data:
Syntax:var var4 = {'ram': 'ranga'};
Numbers:
Syntax:var var4 = 10;
Boolean Values:
Syntax:var var5 = true;
var var5 = false;
Functions:
var var6 = randomInt(2);
Generates a two-digit integer.var var1 = randomStr(2);
Generates a two-letter string.var var2 = randomFloat(3);
Generates a random float.var var3 = uuid();
Generates a UUID.var var4 = randomSlug();
Generates a slug.var var5 = timestamp();
Generates the current timestamp.
Once defined, these variables can be used anywhere using the syntax {{var_name}}
.
#
Example:#
Dothttp Environment & PropertiesIn scenarios where defining variables directly in HTTP files is not ideal (e.g., containing sensitive information like secrets), an environment file can be used to define variables. The environment name can be passed during execution, and all properties in the environment file will be automatically applied.
.dothttp.json
#
Environment File Example: #
HTTP Example:#
PropertiesProperties are useful for setting individual variables without defining an entire environment.
#
System Command VariablesVariables and properties in an environment file or passed through the command line are static. For time-sensitive variables (e.g., access_token
), use System Command Variables to generate them dynamically.
#
Example:In this example, the access_token
variable is generated by running the specified command when accessed.
#
OS Environment VariablesTo use OS environment variables in an HTTP file, prefix the variable name with DOTHTTP_ENV_
.
#
Example:Define or export a variable, such as DOTHTTP_ENV_date
, and access it as {{date}}
in the HTTP request:
#
Math ExpressionsMath expressions can be used for calculations that should not be immediately evaluated. Dothttp handles their expansion and substitution.