thunder-client-support
thunder-client-support copied to clipboard
Enable basic additional operations with setTo
Description
When executing tests and using setTo it would useful to be able to extract values using basic commands, something that we can do with Postman scripting. However, I don't feel we need an entire scripting capability in order to elevate the power of the setTo option.
We can use a simple expression evaluator to add very valuable features.
Example use case
After we call a create user API method (for example in keycloak), it returns a Location header:
http://devhost:8093/auth/admin/realms/app/users/13f239e7-8771-4e75-9c88-341f62650f1b
Example syntax
header.location.split("/")[8] // Split the URL into segments and take the approriate element
This would make the value 13f239e7-8771-4e75-9c88-341f62650f1b available as an environment variable.
After creating a test user it is then possible to delete the same user and clean up.
Postman equivalent
let location = pm.response.headers.get('location').split('/');
let user_id = location[8];
postman.setEnvironmentVariable("kc_new_user_id", user_id);
Thanks @chrisnurse for the feedback, Will add this to roadmap
You're very welcome.
Thank you for this fantastic contribution to the community. I am loving Thunder Client!
I can recommend https://github.com/SujiJoe/ts-expression-evaluator
This has helped me to build several features that need expression evaluation, such as dynamic forms, where some fields need to appear or be invisible based on some flexible logic and values of other input fields. I found it very intuitive.
@chrisnurse glad to know you like the extension 🙂
thanks for suggestion, will look into it.
Hi @rangav , do you have any update on this or any alternate to achieve the same?
@namhuynhkien what is your use-case, can you please share more details
The same as Chris. the response returns the location in the header which contain value needed for next request. e.g. for example I want to get the useCaseId. Below is my script in Postman
var loc= pm.response.headers.get('Location');
pm.environment.set("location", loc);
var firstindex = loc.lastIndexOf('=') + 1;
var requestId = loc.substring(firstindex);
pm.environment.set("use_case_id", useCaseId);
@namhuynhkien thanks for sharing, will implement a solution asap.
Another useful thing would be to be able to base64 decode for example a jwt, and then use one of the json properties inside to set an env variable.
This feature is now implemented and published to marketplace, please update to v2.0.0
See all features released https://github.com/rangav/thunder-client-support/releases/tag/v2.0.0
Please let me know your feedback.
When setting the env variable in Tests tab you can use the format - header.location | split("/") | slice(7, 8) | join
Will implement at filter in the next update
We have implemented at filter in v2.0.1
https://github.com/rangav/thunder-client-support/blob/master/docs/filters.md#at
Now you can header.location | split("/") | at(8)
see release notes here https://github.com/rangav/thunder-client-support/releases/tag/v2.0.1