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

Add format button to response

Open TroyWitthoeft opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Let's add the ability to format the response

Describe alternatives you've considered Formatting the response outside of thunderclient

Implementation: No. But, if the source is shared, I am happy to take a swing at a PR!

TroyWitthoeft avatar Aug 11 '22 14:08 TroyWitthoeft

Hi @TroyWitthoeft, thanks for creating the issue.

Can you share a screenshot of the use-case and also where you want format button?

rangav avatar Aug 11 '22 16:08 rangav

Yes, I can.

image

Can we add a format button to the response pane? I'm envisioning just adding an additional format button on the response pane (above, red line). Something that would let us prettify?

In the example above, we are sending and receiving some complex xml. The response does not contain linebreaks or indentations. It's on a single line and thunder-client struggles with formatting it. However, we're currently using a very popular api suite that CAN pretty-print / format these types of response xml.

Adding this capability would help us adopt thunder-client over our existing standalone api app.

TroyWitthoeft avatar Aug 11 '22 16:08 TroyWitthoeft

Thanks for sharing screenshots. It should format the xml automatically. which could be a bug

What is response content type?, it should be in headers tab? just to clarify the content type.

rangav avatar Aug 11 '22 17:08 rangav

The response type coming out of that server is text/html; charset=utf-8 So, it's clear why it's not being automatically formatted. However an optional format button could help in these types of situations! 😄 Any chance we can add one?

TroyWitthoeft avatar Aug 11 '22 17:08 TroyWitthoeft

Thanks for clarifying. If you can update the content-type this should be fixed.

If we provide Format button also, it would be based on content type right?

the format functionality should know what type of content - to format correctly.

rangav avatar Aug 11 '22 17:08 rangav

If we provide Format button also, it would be based on content type right?

I mean, that is a convenient way to do it, yes. But, it also creates a dependency on the remote client setting the content-type accurately. That may not always be the case.

What about a format button that was a dropdown between, xml, json, and text and would just let the user apply prettification after the response arrived? It's not automatic, but it IS flexible, and it would handle these types of situations.

Again, other "bigbox" api clients are not relying on the content-type of the remote server.
Maybe we should take a look and see if insomnia /hopscotch rely on that content-type setting? Perhaps it's only a thick client like postman that doesn't? What format detection methods are being used there?

TroyWitthoeft avatar Aug 11 '22 17:08 TroyWitthoeft

Thanks for the suggestion, Will add to roadmap for manual format button.

rangav avatar Aug 11 '22 17:08 rangav

Thanks, and happy to recon other clients for you to see if they have lightweight way of intelligently deciding what type of formatting should be applied in situations where the response body and content-type disagree.

TroyWitthoeft avatar Aug 11 '22 17:08 TroyWitthoeft

I have tested on insomnia, with wrong content-type, it does not format. Screenshot 2022-08-11 at 18 44 49

rangav avatar Aug 11 '22 17:08 rangav

you can use this url to test yourself https://www.thunderclient.com/t/echo

Add request header content-type - text/html

and this in xml body

<test><name>abc</name><loc>test</loc></test>

rangav avatar Aug 11 '22 17:08 rangav

Thanks my working example is postman. It does detect and format for me. Haven't checked others.

TroyWitthoeft avatar Aug 11 '22 17:08 TroyWitthoeft

actually there is alternative option in thunder client, you can open the response in vscode and let vscode format it for you..

Screenshot 2022-08-11 at 18 49 40

rangav avatar Aug 11 '22 17:08 rangav

This is very much similar to having a manual format button. let me know what you think?

rangav avatar Aug 11 '22 17:08 rangav

That's a decent workaround! But, it is an extra hop and click for users.
I guess I'm trying to get thunder up to feature parity with peers.
I recently had a dev say they wouldn't adopt it because postman formats and thunder doesn't.
Will point this one out to them.

image

TroyWitthoeft avatar Aug 11 '22 17:08 TroyWitthoeft

Thanks for feedback. Will add to roadmap.

rangav avatar Aug 11 '22 18:08 rangav

Found some detail on hoppscotch approach here https://github.com/hoppscotch/hoppscotch/blob/c1cc1ce2955d6b82a82a53cdae54830220431084/packages/hoppscotch-app/helpers/curl/sub_helpers/contentParser.ts

TroyWitthoeft avatar Aug 12 '22 13:08 TroyWitthoeft

Thanks @TroyWitthoeft for sharing the info, will look into it.

rangav avatar Aug 12 '22 14:08 rangav

strange hoppscotch does not do auto format based on content.

Screenshot 2022-08-12 at 17 30 34

rangav avatar Aug 12 '22 16:08 rangav

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

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

Please let me know your feedback.

rangav avatar Aug 14 '22 19:08 rangav

Just retested with latest version of thunder-client and all looks good! Returned xml is automatically formatted even if the remote server is not correctly setting the content-type header.

Thank you, and impressively quick work! 🤯
Let's mark this as resolved, and let me know how I can be of service in the future!

TroyWitthoeft avatar Aug 15 '22 19:08 TroyWitthoeft

Thanks @TroyWitthoeft for confirmation :)

Any feedback to further improve the product is appreciated very much.

rangav avatar Aug 15 '22 20:08 rangav