Hoppscotch CLI
Run tests, manage automated API monitoring, and more.
Hoppscotch gives you multiple ways to interact with and configure your APIs. With the command-line interface (CLI) you can interact with the Hoppscotch platform using a terminal, or through an automated system. This enables you to run API tests, manage automated API monitoring, and more.
This section contains a complete list of all Hoppscotch CLI commands available, alongside their optional parameters for additional behavior. You can also find a complete list of configuration options to configure your APIs through Hoppscotch.
Pre-requisites
Before installing the Hoppscotch CLI, ensure your system meets the following requirements.
Installing Hoppscotch CLI
Once the dependencies are installed, install @hoppscotch/cli from npm by running::
npm i -g @hoppscotch/cli
Commands
hopp test
The hopp test
command allows you to run tests against a Hoppscotch collection file.
- The hopp test command recursively goes through each request in the collection and runs them, validating the responses with the test script provided in each request. Hence, the order of execution is the same as the order specified in the collection structure.
- If upon executing the command, a failed assertion (a failing test case) has occurred, the command will give a non-zero exit code and 0 exit code if all tests have passed.
- Unless there was a network error (for example, DNS resolution errors or network Connectivity Issues), the test script will be running and it is up to the test script to define what happens to error status codes. Non-200 status codes are still considered valid responses for test script execution.
- The execution of requests within a collection can be deferred using the
-d, --delay
flag. One practical application involves executing requests against APIs with enforced rate limits.
hopp test [-e <environment file>] [-d <delay_in_ms> ] <hoppscotch collection file>
Example
hopp test kitchen-sink-hoppscotch-collection.json
hopp test -e environment.json kitchen-sink-hoppscotch-collection.json
hopp test -e environment.json -d 1000 kitchen-sink-hoppscotch-collection.json
Environment
Hoppscotch allows templates in several places. For example, you could specify your endpoint URL as <<baseurl>>/post
and specify baseurl as https://echo.hoppscotch.io
in an environment file.
Hoppscotch CLI supports environment files in two specific formats:
1. Single Environment Entry Export Format
This format is generated by Hoppscotch App when you export any of your environment. It includes a named environment (name) with key-value pairs, allowing you to define various variables within a single file.
{
"name": "my_env",
"variables": [
{
"key": "base_url",
"value": "https://echo.hoppscotch.io"
},
{
"key": "auth_token",
"value": "xxxxxxxxxxxx"
}
]
}
2. Legacy Export Format
Hoppscotch CLI continues to support the legacy format which was previously the only accepted format used by CLI.
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
Secrets
If requests in a collection consists of secret variables we recommend either of the two approaches.
- Inject the secret values as variables into the OS environment
- Edit the environment export file and add the secret values manually
Options
Option | Description |
---|---|
-h | Gives a list of associated commands and their descriptions |
-v | Displays the curremt version of the CLI |