lostisland/faraday

Query parameters doesn't respect hash

sdalu opened this issue · 2 comments

sdalu commented

Basic Info

  • Faraday Version: 2.3.0
  • Ruby Version: 3.0

Issue description

When performing a GET request with query parameters, the parameters seems to be re-ordered in alphabetical order.
Which is an issue as some web site doesn't parse all parameters at once and behavior will differ due to parameter ordering

Steps to reproduce

Faraday.get('http://httpbin.org/get', :b => 1, :a => 1)

Anwser show that the request was: http://httpbin.org/get?a=1&b=1
Instead of expected: : http://httpbin.org/get?b=1&a=1

I'm sorry @sdalu I must have missed your issue and I just saw it!
That is the default behaviour which is really useful for caching, but if for whatever reason you need to control the parameters order, you can disable that on the ParamEncoder you're using:

# NestedParamsEncoder is the default
Faraday::NestedParamsEncoder.sort_params = false
# or if you're using FlatParamsEncoder
Faraday::FlatParamsEncoder.sort_params = false

Actually let me keep this open, I just realised this is not documented on the website so I'd like to add it 🙌 !