usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.7k stars 1.28k forks source link

Allow response headers to be changed #3495

Open drwelby opened 1 week ago

drwelby commented 1 week ago

I have checked the following:

Describe the feature you want to add

In https://github.com/usebruno/bruno/issues/2441 the request body could be updated. This is useful to convert less human-friendly response bodies into structures that are more legible.

However, since it appears the application relies on the content-type header to determine how to display the result, this mean that while it is possible to convert the response between formats, the contents will only render as the original format.

A common use case is with APIs that return a response in the GeoJSON format. This standard represents spatial objects like polygons and points on a map. It is helpful to be able to see the results as a map instead of as a string of characters.

An example of this in Postman is https://github.com/OrdnanceSurvey/postmanGeoJSON. The GeoJSON response body is inserted into HTML code to be rendered in the response.

Bruno can render similar content in the response correctly already - a GET request of https://leafletjs.com/examples/quick-start/example.html works fine in the "web" preview in the response panel.

Mockups or Images of the feature

The following functions would be exposed in responses, following the same syntax for requests:

res.setHeader()
res.setHeaders()

This would look like (skipping the HTML generation code):

Screenshot 2024-11-15 at 11 40 30 AM
drwelby commented 3 days ago

The additional functions seemed straightforward to add so I created a PR: https://github.com/usebruno/bruno/pull/3527