lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.

Home Page:https://lostisland.github.io/faraday

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query parameters doesn't respect hash

sdalu opened this issue · comments

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

commented

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
commented

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