Thunder Client Guide: How to Convert Postman Script
Thunder Client is a streamlined and powerful API client available as a VS Code extension. It's lighter and quicker than other heavy-duty API clients. If you’ve been using Postman but are looking for a change, converting your Postman scripts to Thunder Client can be done effortlessly.
Thunder Client is a streamlined and powerful API client available as a VS Code extension. It's lighter and quicker than other heavy-duty API clients. If you’ve been using Postman but are looking for a change, converting your Postman scripts to Thunder Client can be done effortlessly. Below, we've put together a comprehensive guide.
What is Thunder Client?
Thunder Client is an API testing client incorporated directly within Visual Studio Code. Known for its simplicity and speed, it’s ideal for developers who prefer to work within VS Code without hopping between different applications. It supports various request types and offers scripting capabilities similar to Postman.
How to Convert Postman Scripts to Thunder Client
Switching from Postman to Thunder Client involves understanding the mapping between Postman and Thunder Client variables, libraries, and methods. Here’s a detailed look at how these map out:
Global Variables
Postman to Thunder Client Mapping
In Postman, you might use variables like pm
or functions like pm.expect
. Here’s what their Thunder Client counterparts are:
Postman Variable | Thunder Client Variable |
---|---|
pm |
tc |
pm.expect |
expect |
pm.assert |
assert |
btoa |
btoa |
atob |
atob |
Built-in Libraries
Thunder Client doesn’t leave you in the lurch when it comes to built-in libraries. Here's a comparison of what libraries are available:
Postman Library | Thunder Client Library |
---|---|
ajv |
ajv |
ajv-formats |
|
axios |
|
atob |
atob |
btoa |
btoa |
buffer |
buffer |
chai |
chai |
cheerio |
tc.loadModule('cheerio') |
crypto-js |
crypto-js |
csv-parse/lib/sync |
papaparse or tc.loadModule('csv-parse') |
fs |
|
http |
|
https |
|
lodash |
tc.loadModule('lodash') |
moment |
tc.loadModule('moment') |
stream |
stream |
tough-cookie |
|
tv4 |
tc.loadModule('tv4') |
url |
url |
util |
util |
uuid |
uuid |
xml2js |
fast-xml-parser |
Requests and Responses
Mapping request and response properties is crucial for the successful conversion of your scripts.
Request Properties
Postman Property | Thunder Client Property |
---|---|
tc.request.id |
|
tc.request.name |
|
pm.request.url |
tc.request.url |
pm.request.method |
tc.request.method |
pm.request.headers |
tc.request.headers |
pm.request.body |
tc.request.body |
tc.request.getHeader() |
|
pm.request.headers.add() |
tc.request.setHeader() |
pm.request.headers.remove() |
|
tc.request.setBody() |
Response Properties
Postman Property | Thunder Client Property |
---|---|
pm.response.code |
tc.response.status |
pm.response.responseTime |
tc.response.time |
pm.response.responseSize |
tc.response.size |
tc.response.contentType |
|
pm.response.json() |
tc.response.json |
pm.response.text() |
tc.response.text |
pm.response.headers |
tc.response.headers |
tc.response.cookies |
|
tc.response.getHeader() |
Info Functions
To extract extra information about the request in execution:
Postman Property | Thunder Client Property |
---|---|
pm.info.eventName |
|
pm.info.iteration |
tc.info.currentIteration |
pm.info.iterationCount |
tc.info.totalIterations |
pm.info.requestId |
tc.request.id |
pm.info.requestName |
tc.info.requestName |
pm.environment.name |
tc.info.environmentName |
tc.info.collectionName |
|
tc.info.folderName |
Environment Methods
How to handle environment variables in Thunder Client:
Postman Methods | Thunder Client Methods |
---|---|
pm.variables.get() |
tc.getVar() |
pm.variables.set() |
tc.setVar() |
pm.collectionVariables.get() |
tc.getVar() |
pm.collectionVariables.set() |
tc.setVar() |
pm.environment.get() |
tc.getVar() |
pm.environment.set() |
tc.setVar() |
pm.globals.get() |
tc.getVar() |
pm.globals.set() |
tc.setVar() |
pm.iterationData.get() |
tc.getVar() |
Methods
Translating Postman methods to Thunder Client:
Postman Methods | Thunder Client Methods |
---|---|
pm.cookies.has() |
|
pm.cookies.get() |
tc.getCookies() |
pm.cookies.jar().set() |
tc.setCookie() |
pm.cookies.jar().getAll() |
tc.getCookies() |
pm.cookies.jar().unset() |
tc.clearCookies() |
pm.cookies.jar().clear() |
tc.clearCookies() |
pm.sendRequest() |
axios or tc.runRequest() |
pm.execution.skipRequest() |
tc.skipRequest() |
postman.setNextRequest() |
try using tc.skipRequest() |
pm.visualizer.set() |
tc.chartView() |
pm.test() |
tc.test() |
pm.expect() |
expect() |
Final Thoughts
Switching from Postman to Thunder Client is not just simple, but also beneficial if you work extensively in VS Code. Thunder Client's lightweight nature and robust feature set ensure that you won't miss a beat.
And while Thunder Client is a fantastic tool, if you’re looking for an even more lightweight and no-login-required alternative, consider EchoAPI for VS Code. EchoAPI is perfect for collaboration and supports the Postman script syntax fully, making the transition smooth.
Why EchoAPI for VS Code?
- No login required: Start using right away without creating an account.
- Supports Scratch Pad: Work on APIs without the need for persistent storage.
- Ultra-lightweight: No more waiting for heavy applications to load.
- 100% compatible with Postman script syntax: Seamlessly switch between tools.
You can also find EchoAPI plugins for IntelliJ IDEA, Chrome request capture extension, and more, making it an excellent all-around tool for API development.
By following this guide, you can confidently transition your Postman automation scripts into Thunder Client and possibly explore EchoAPI for optimum efficiency.