A tool for executing API queries defined in a plaintext file that can be checked in to version control or managed like any other file.
The basic workflow goes like this:
- Create the configuration file with
variablesandqueriessections - Populate the
variableswith values that you wish to use throughout the queries - Specify queries and the details that should be use for the requests
- Run any query using
inq query <query>
The configuration uses the kdl format.
Variables are the way to have central values and customise behaviour at
runtime. All variables may be overridden with --var KEY=VALUE on the
commandline.
Most strings support interpolation using rhai with the syntax
${expression}. Each variable in the variables block is defined in
the scope and may be used as a value in the expression. (NOTE: all
variables are strings and my be converted into other values using the
rhai functions).
Variables can be specified in three different ways:
foo <value>- Use a specific valueenv=<variable>- Always read the value from an environment variablefile=<file>- Use the contents of a file as the variable (whitespace trimmed)
Variables may additionally be marked as persist. These variables
will be saved to a file and hold their values between queries.
To mark a variable to persist, add persist=#true or persist="<time>"
where <time> is a duration, like 1 hour.
These go in the variables section:
variables {
PORT 3000
BASE_URL "http://localhost:${PORT}"
USER env="USERNAME"
PASSWORD file="password.txt"
COOKIE "" persist=#true
}Variables that have been marked as persist can be updated using the
inq variable subcommand:
inq var[iable] set <variable> [value] [--expires=<time>]
inq var[iable] get <variable>
inq var[iable] list
Queries are the basic requests, any number of which may be specified in
the queries section.
Each query is specified using
<NAME> <METHOD> <URL> {
// configuration
}The configuration may contain the following items:
headers- a map of string to string that will be used to set the request headersbody- Set the body of the request using eithertext=<string>orjson=<string>. Ifjsonis used, thecontent-typeheader is automatically set toapplication/json.post-script- A rhai script to run after the request is complete. This can be used for updating variables
variables {
PORT 3000
BASE_URL "http://localhost:${PORT}"
USER env="USERNAME"
PASSWORD file="password.txt"
COOKIE "" persist=#true
}
queries {
login POST "${BASE_URL}/login" {
headers {
user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0"
}
body json="""
{
"username": "${USER}",
"password": "${PASSWORD"}
}
"""
post-script #"""
let cookie = parse_cookie(response.headers["set-cookie"]);
vars.COOKIE.value = cookie.value;
vars.COOKIE.expires_at = cookie.expires;
"""#
}
}And then run it with
inq query login
# override variables with
inq query login --var USER=someone-else