Thunder Client CLI — A new way to test APIs inside VS Code
In 2021, we launched Thunder Client extension for VSCode which was a game changer as we were the first to launch a GUI based API client inside VSCode. Today we are launching Thunder Client CLI which will have many innovative features for API testing.
Key Features
- Simple & Easy to Use CLI tool
- Seamless Integration with Thunder Client Extension
- Run Requests/Collections and View Test results
- Syntax Highlighting and VSCode Themes
- Open Request/Collection UI from the terminal
- Enhances cURL commands
- CI/CD Integration
Requirements
- Node 18 or higher
- Thunder Client Subscription is required***
Installation
- Please update the extension to latest version
- Install CLI —
npm i -g @thunderclient/cli
- Note : Please make sure the commands are run from the root of the project.
VS Code Settings
- If you are using Thunder Client settings in the extension, make sure they are in
workspace
scope for the CLI to access them. - If you are using
Multi-root
workspace then use the folder tab for settings
Run Requests
The CLI and Extension are integrated seamlessly, so you can access requests data from the terminal without any additional configuration.
- To execute requests run
tc 'requestNameOrId'
, the request can be executed using id, name or partial name
As you can see in the above image, executing requests is very easy from CLI. The output is formatted beautifully with Status, Response with Syntax highlighting & VSCode theme, and Test results.
To Run the same request from UI requires multiple steps as below
- Open Sidebar
- Click Collections Tab
- Open collection
User
and folderAccount
- Then open
Welcome
request - Now execute the request
Output Log
When the user executes a request by default — Status, Response & Test Results are displayed. You can control the data to output with --log
argument.
- Log options for request: 0=All Data, 1=ReqHeaders, 2=ReqBody, 6=ResHeaders, 7=ResBody, 8=Tests
- Example:
tc 'welcome' --log 1,2,7
will display Req headers, Req Body, and Response Body.
Open Request UI from CLI
If you like to quickly execute a request in extension UI, then you can do it easily from CLI using--ui
argument.
tc 'welcome' --ui
To open a request in UI and execute automaticallytc 'welcome' --ui2
To open a request in UI without auto-run.
VSCode Themes In Terminal
We are bringing VSCode themes to the terminal for the first time.
Run Collection
Collection Runner will execute all the requests in the collection and display output in a beautiful format similar to the extension UI.
tc --col 'colNameOrId'
will run requests in the collection from CLI
Run All Collections
tc --col all
will run all the collections from CLItc --col all --skip "ColA,ColB"
will run all collections except ColA & ColB.
Run Multiple Collections
tc --col "colNameOrId1,colNameOrId2"
will run multiple collections from CLI
Run Collection Parallel
tc --col 'colNameOrId' --concurrent 5
will run 5 requests at a time in parallel from CLI.
Run Folder
tc --fol 'folNameOrId'
will run requests in the folder from CLI
Run Selected Requests
tc --reqlist "nameOrId1,nameOrId2,nameOrId3"
will run selected requests from the collection
Environment
By default the collection or request will use active environment. if you like to run using different environment, then use --env
argument.
- Example:
tc --col 'colNameOrId' --env 'Staging'
Reports
CLI can generate reports in xml, html, json and csv formats.
tc --col 'User' --report xml,html
command will execute all the requests and save reports in thunder-reports folder
Open Run Collection UI from CLI
If you like to execute Run collection in extension UI quickly, then you can do it easily from CLI using--ui
argument.
tc --col 'User' --ui
To open a collection runner in UI and execute automaticallytc --col 'User' --ui2
To open a collection runner in UI without auto-run.
List Collections or Requests
tc list
to display the list of all collections
tc list user
to display the list of requests in collection ‘User’
List Environments
tc list env
will display list of all environments
Enhances cURL Commands
In the above we have seen how to run requests and collections easily from CLI. Thunder Client CLI also has integration with cURL commands, so you can use it to create requests from CLI.
Standard cURL Command
Run cURL command using TC CLI
Run cURL command by prefixing tc
and see the magic. By using Thunder Client CLI you will get the following benefits over normal cURL.
- Formatted Output
- Syntax Highlighting & VSCode Themes
- Request history will be saved to your Activity Tab
Save Request to Collection/Folder
You can also save requests to collection or folder using cURL command from CLI.
tc curl 'http://httpbin.org/anything' --name 'Curl Req1' --col User
the command will add request to collection User with name Curl Req1- Use
--col
argument to save to collection, and--fol
argument to save to folder, and--name
to specify the name of request
CI/CD Integration
Thunder Client CLI can be used in build server to run collection and save reports in xml, html, json and csv formats.
- VS Code Settings: If you are using any TC VSCode settings, they need to set the scope to workspace, so the settings will be saved to the workspace directory.
- Git Sync: The collection runner in build server will work only when you enable git sync feature
tc --col "ColNameOrId" --report "xml,html"
command will execute all the requests and save reports in thunder-reports folder
Github Actions
- The sample yaml file can be used to integrate with Github actions or other build pipelines
Workspace Location
- [Optional] The CLI will use the current working directory as workspace directory, but if the data is in different workspace directory then use the
--ws 'fullpathToGitWorkspace'
to specify the workspace path.
Stop Collection When Fail
- [Optional]: If you want to stop collection execution of other requests when a request test fails then use the argument
--stop-on-fail
Help Screen
The help screen for most CLI tools is boring and difficult to understand. So I custom designed our CLI help screen to be colorful and easy to understand.
Debug Information
If you have issues with the CLI reading data or reading the git-sync settings, run the debug command to see useful information.
- Run the debug command using —
tc --debug
- This will display the directory path where the CLI is trying to read the data and the git-sync settings values used.
Feedback
We love to hear your feedback about our new CLI tool, Please use it and let me know if any further improvements can be done in the comments or GitHub page.
- Website: www.thunderclient.com
- Support: thunder-client-support