Variables
#
Variablesone can define variables in http file via {{var}}
. define it once and use it everywhere
#
example 1:python -m dothttp test.http
In the above httpdef
, var is set to get
. one can overwrite it via
python -m dothttp test.http --properties var=post
producing
curl -X GET 'https://httpbin.org/post?path=post'
#
example 2:curl output will be
override via properties by passing in command line
python -m dothttp --properties name=shiva lastname=prasanth
#
Dothttp Environmentpassing properties from command line is not always handy. one can define
.dothttp.json
in same directory as http file
#
randomwhile integration testing, having to replace few fields are pain points. using $randomStr will generate random string of random length.
- random string ($randomStr)
- random integer ($randomInt)
- random float( $randomFloat)
- random bool ( $randomBool)
name --> shiva + "randomString of length 10 chars" height --> randomInteger of length 2
made request will like below
#
uuiduuid is completely random string with 36 char length
#
Example#
randomSlugrandomSlug
or randomLoremSlug
we’ll see random, human-readable slugs (e.g., brave-purple-penguin) in the web development world. These slugs offer the uniqueness of a number ID but can be more playful and fun.
{{$randomSlug:3}}
--> create slug with 3 (brave-purple-penguin
)
{{$randomSlug:2}}
--> create slug with 3 (brave-ranga
)
#
example#
timestampWhile testing, uniquely identifiying request is hard, one can use timestamp (epoch) in headers or queryparams to distinguish from ther requests
usage:
{{$timestamp}}
--> generates 1629338487
(current timestamp)
#
Example:#
System CommandEnvironment file variables and properties defined in a file or through the command line are static. However, some variables—such as access_token
or sts
—are time-sensitive and must be generated dynamically when needed.
System Command Variables are those that can be generated on demand by running a command in the command line.
To define a system command variable, create a key-value pair in the $commands
section of your environment file. Here’s an example:
In this example, the access_token
is set up to be generated dynamically by executing the specified command when accessed.
#
Os Environment Variables:To use an OS environment variable in an HTTP file, prefix the variable name with DOTHTTPENV.
#
Example:Define or export a variable, such as DOTHTTP_ENV_date, to use {{date}}
it in the following HTTP request:
In this example, DOTHTTP_ENV_date can be accessed as {{date}}
within the HTTP request.
#
Math Expression:You can use simple math expressions that you may not want to evaluate immediately for debugging purposes. Dothttp handles the expansion and substitution for you.