sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Not possible to send query array parameter in coma separated format #1368

Closed pawelusfr closed 4 years ago

pawelusfr commented 4 years ago

Describe the bug

I need to send a query parameter that is an array in comma separated format e.g. htts://someurl.com?users=user1,user2 In got 9.6.0 it was possible using query-string module as described in documentation In got 11.5.1 that part of documentation about query-string is gone and got will url escape the searchParams no matter what I try (query-string or URLSearchParams)

Actual behavior

got url escapes searchParams and will send the request to http://someurl.com?users=user1%2Cuser2

Expected behavior

got should not escape searchParams and send the request to htts://someurl.com?users=user1,user2

Code to reproduce

const users = ['user1', 'user2'];
const result = got.get('http://someurl.com', {searchParams: new URLSearchParams({users})});
...

Checklist

414412 commented 4 years ago
                return retryWithMergedOptions(updatedOptions);
szmarczak commented 4 years ago

You need to pass the search string in a URL:

require('got').get('https://httpbin.org/anything?users=a,b,c').json();
szmarczak commented 4 years ago

That's because the search string doesn't have to be a query string.