pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.08k stars 1.6k forks source link

Unexpected query string when passing params containing an array #710

Open tomqwpl opened 5 years ago

tomqwpl commented 5 years ago

The documentation is unclear on the expected behaviour of this, but it's unexpected to me. I'm invoking something like:

Vue.http.get('http://somewhere/something',` { params: { field: ['a', 'b'] } })

That is, I want to pass a query parameter containing a list of values. Naively, I expect the query string to be: http://somewhere/something?field=a&field=b

But instead I get: http://somewhere/something?field[]=a&field[]=b

(the [] are URL encoded, I've decoded them head to make it more obvious)

Is this expected? I can't find any tests that explore this. In my experience, at least with java as the endpoint, if you're expecting an array of values, you just repeat the query parameter, you don't put "[]" on the end. I can't actually find a workaround to this. I can't find a method of constructing the query string I want, except for doing it manually and passing the result in as the URL.

flavio-b commented 5 years ago

@tomqwpl , I believe it is a convention in other frameworks (in Rails for sure, and probably PHP's), to accumulate the values in array, for a parameter like key[].

bloor commented 3 years ago

Unfortunatelly there's no work around and I can change the "convention" since gDrive File Api specifically tells me to use this query parmater 'root' in parents and properties has { key='sid' and value='1018' }

How am I supposed ta achieve that ? The $http strips/parses my query string as 'root' in parents and properties has it stops whenever it reaches "{" .

I see it as a flaw, issue, bug. The jQuery alternative works ok: ie it does not alter my parameters.