usebruno / bruno

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

Alow Bruno to URL-encode query params, similar to curl's `--url-query` #1775

Open bkane-msft opened 6 months ago

bkane-msft commented 6 months ago

Hello! An API we have to use has query params that need to be URL encoded. We can do this with curl like this:

curl https://endpoint.com/path --url-query "results=a,b,c"

However, when trying Bruno, I realized I had to manually URL encode this myself:

image

Is there a way to be able to add query params that need to be URL encoded in Bruno? Perhaps similar to the "Body" dropdown (see next screenshot for example) that allows Form Encoding: image

bkane-msft commented 6 months ago

To add a little more context to this, I tested two other HTTP clients (Hurl - Run and Test HTTP Requests and REST Client - Visual Studio Marketplace) and they each auto-URL-encode query params for me. I'm not sure that's the correct behavior, but it's something I need to ergonomically work with these params. Other than this, Bruno looks awesome, thanks for making it!

Hurl example

GET https://endpoint.com/path
[QueryStringParams]
results: a,b,c

REST Client example

GET https://endpoint.com/path
    ?results=a,b,c
patclrk commented 6 months ago

+1

It looks like Postman implements this as a "setting" on the Request itself (not global), which is also handy:

image
flx-sta commented 5 months ago

+1

Reading a little into the code it seems like axios is being used to send requests and axios should be capable of this feature.


This might be a duplicate of #732

randoogle commented 1 month ago

I would love to have this feature. For now, I've put this workaround into my Collection's Pre-Request Script, which splits the request URL into hostname, etc. and parameters, and URI encodes the parameters. So far it hasn't had any issues, but your mileage may vary:

req.setUrl(req.getUrl().replace(/(.+?\?).+/,'$1') + encodeURI(req.getUrl().replace(/.+?\?/,'')))
randoogle commented 1 month ago

Oh, I'm just realizing now that one big issue with my work-around is that the variables aren't getting interpreted before the JavaScript runs (see #2690). I understood this initially, which is why I split the host and parameters apart, but I'm just realizing it makes using variables in the parameters impossible.