I have an endpoint in my application that returns data based on the given query string. The query string can (and often has to) contain duplicate keys, for example /api/entities/related?filter1=val1&filter1=val2&filter2=val3
to identify two filters of type filter1
. Flask deals with this nicely, for example when doing request.args.to_dict
, I would get {'filter1': ['val1', 'val2'], 'filter2': 'val3'}
.
My question is how to achieve the same thing with Backbone when fetching a collection from an endpoint. Currently I might have
this.fetch({data: {'filter1': 'val1', 'filter1': 'val2', 'filter2': 'val3'}});
Since duplicate keys will override each other in javascript objects, my filter1
value will end up being val2
. However, when doing
this.fetch({data: {'filter1': ['val1', 'val2'], 'filter2': 'val3'}});
the url ends up being /api/entities/related?filter1%5B%5D=val1&filter1%5B%5D=val2
, which at least does use two identical keys but obviously does not work.
Is this an encoding problem or should I approach it differently?