thunder-client-support icon indicating copy to clipboard operation
thunder-client-support copied to clipboard

Ability to chain requests (like Insomnia REST client)

Open saefren opened this issue 4 years ago • 10 comments

Right now we can save (part of) the response of a request (for example, an access-token, let's call this request Authenticate) to a variable, which can then be used in another request. However, this access-token will expire. You'll find this out when performing the main request. You'll then have to go back to the Authenticate request and re-send it so it updates the access-token variable. This becomes really cumbersome when there are multiple requests depending on each-other.

In Insomnia we can chain requests via Tags and specify a Trigger Behavior: image

In addition it would be very nice if the dependent request could also be triggered when the depending request fails (for example 401 unauthorized). This could happen for example when the back-end application resets without persistent token-state.

And super nice would be if we would see this dependency-chain in action in some window/widget.

I am sorry if this is already possible. I did not find such feature.

saefren avatar Jul 02 '21 12:07 saefren

Hi @saefren currently this is not in roadmap, but we have plans to auto-renew token when it expires, based on expiry date.

rangav avatar Jul 02 '21 13:07 rangav

That is very nice.

However, it's not just for tokens. It is possible multiple requests are chained to each-other. For example Authenticate > Get account info > Create a cart with line-items > Convert the cart to order > Confirm order. Each request needs some information from one or more previous requests.

I might be developing a new feature: Cancel order. I need to create new orders to test the 'Cancel order' feature. In Insomnia I just click 'Confirm order' and it does all the other steps because the requests have been chained. I could also chain 'Cancel order' to 'Confirm order' and it becomes a one-click test.

Now, perhaps at this point this example should become an automated regression test, but it's still a feature I use daily with Insomnia.

Is it something you would consider putting on the roadmap if there is animo (I suspect there is). For me it's the only issue preventing me making the switch to Thunder Client :)

saefren avatar Jul 02 '21 14:07 saefren

You can add the requests in collection in the order you want, and then you can run collection with Run All. which execute all the requests in order as needed.

you can group the requests into folder also.

Did you try this?

rangav avatar Jul 02 '21 18:07 rangav

I guess this could help in some cases. But I don't think this is a very usable strategy (especially with bigger projects).

I am using collections & folders to group / give structure to the requests, however this structure doesn't have much to do with their dependencies.

As some requests are used by multiple other requests, I would have to create copies of said requests (which would of course result in more maintenance).

saefren avatar Jul 02 '21 19:07 saefren

ok got it, will think about it, there is also request for pre-request script, will review this when i am implementing scripting.

rangav avatar Jul 02 '21 19:07 rangav

In Postman you can chain requests using 'Pre-Request Script', however this is a bit of a hack / workaround. It's also painful to maintain because each request has it's own Pre-Request Script copy. So if this script needs a change you have to find all the requests that use this script and change it there.

That is why I have switched to Insomnia REST Client, which has chaining built in through their Tag system (which can be used anywhere!)

saefren avatar Jul 02 '21 19:07 saefren

Ah, you just mentioned the pre-request script :)

It's a nice to have feature but as I explain in the previous comment, not a very good alternative to Insomnia's Tags..

saefren avatar Jul 02 '21 19:07 saefren

PS: very nice extension... Especially if it's possible to commit the project to a repository (Teams feature which is beta?). This is essentially where Postman and Insomnia make their money as the sharing goes through their paid service.

Also, where is your donate button? :)

saefren avatar Jul 02 '21 19:07 saefren

Thats a good point @saefren, you mentioned about pre-request script. haven't yet planned how to implement pre-request script . will update this discussion when i plan to implement it.

About Team Features: you can share with team via git integration https://github.com/rangav/thunder-client-support#team

its still in beta because, i am still getting good feedback for improvements as more people using this feature . So there is still room for improvements for this feature.

rangav avatar Jul 02 '21 19:07 rangav

Hi All, started work on request linking. here is the preview screenshot of the feature. let me know your feedback

Advanced scripting will be implemented at later stage.

rangav avatar Mar 08 '22 14:03 rangav

I'm only waiting this feature to use Thunder in my company projects!

ricardocastanho avatar Oct 05 '22 18:10 ricardocastanho

@ricardocastanho this feature is in my priority list, will implement soon.

rangav avatar Oct 05 '22 21:10 rangav

Hi All, Good News. This feature development is now completed. Planning to publish tomorrow.

Would anyone like to Test now and give feedback? I can upload the VSIX file here

rangav avatar Oct 11 '22 15:10 rangav

Hi All, Good News. This feature development is now completed. Planning to publish tomorrow.

Would anyone like to Test now and give feedback? I can upload the VSIX file here

I would like to test!

ricardocastanho avatar Oct 11 '22 18:10 ricardocastanho

Please find the vsix file.

The tab is called Pre Run, available at request and collection settings

vscode-thunder-client-1.19.8.vsix.zip

please let me know your feedback.

rangav avatar Oct 11 '22 18:10 rangav

Please find the vsix file.

The tab is called Pre Run, available at request and collection settings

vscode-thunder-client-1.19.8.vsix.zip

please let me know your feedback.

It works fine! But how can I get a field, like a token returned from an auth request, in the Pre Run?

ricardocastanho avatar Oct 11 '22 20:10 ricardocastanho

Please find the vsix file.

The tab is called Pre Run, available at request and collection settings

vscode-thunder-client-1.19.8.vsix.zip

please let me know your feedback.

Looks good but could the requests drop-down be in alphabetical order? It would be much easier to find the request we are looking for

Edit: Probably would be better to order the requests by their order in the sidebar

andresatierf avatar Oct 11 '22 21:10 andresatierf

Please find the vsix file. The tab is called Pre Run, available at request and collection settings vscode-thunder-client-1.19.8.vsix.zip please let me know your feedback.

It works fine! But how can I get a field, like a token returned from an auth request, in the Pre Run?

You can use Tests tab in Pre Req to save token to a variable and then access it in the main request as {{variable}}

rangav avatar Oct 12 '22 04:10 rangav

Please find the vsix file. The tab is called Pre Run, available at request and collection settings vscode-thunder-client-1.19.8.vsix.zip please let me know your feedback.

Looks good but could the requests drop-down be in alphabetical order? It would be much easier to find the request we are looking for

Edit: Probably would be better to order the requests by their order in the sidebar

Will update the order, to match the sidebar list order.

rangav avatar Oct 12 '22 04:10 rangav

This feature is now implemented and published to marketplace, please update to v1.20.0

See all features released https://github.com/rangav/thunder-client-support/releases/tag/v1.20.0

Please let me know your feedback.

rangav avatar Oct 12 '22 11:10 rangav

@rangav instead of linking it to a request, it'd be better (maybe also) linked to a variable or collection-wide. E.g. I have 10 requests where I need to login, it'd be easier to login before all requests of a collection.

hyoretsu avatar Oct 13 '22 14:10 hyoretsu

Hi @hyoretsu you can add pre-request at request, folder and collection level. Please open collection settings to see Pre-Run tab

Screenshot 2022-10-13 at 16 17 48

rangav avatar Oct 13 '22 15:10 rangav

Right now we can save (part of) the response of a request (for example, an access-token, let's call this request Authenticate) to a variable, which can then be used in another request.

I'm curious – how would I do that? 😳

metawops avatar Mar 21 '24 15:03 metawops

@metawops from the Tests tab, select Set Env Variable option

Docs here https://github.com/rangav/thunder-client-support/blob/master/README.md#setenv

rangav avatar Mar 21 '24 17:03 rangav