I'm new to Faraday and trying to learn how to pass an array for url params. My code looks like this:
require 'faraday'
conn = Faraday.new(:url => 'http://foo.com:8888') do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
response = conn.get '/api/endpoint', { :bar => ['baz', 'qux'] }
response.body
When I debug, I see that the URL is getting encoded as:
INFO -- : get http://foo.com:8888/api/endpoint?bar[]=baz&bar[]=qux
instead of http://foo.com:8888/api/endpoint?bar=baz&bar=qux
. How do I get faraday to encode the URL without the []
when I'm passing an array of params?
I see why this is happening now.
This issue is actually fixed on Faraday ver 0.9+, but that's only avaliable as an RC.
So two choices: Change your code to look like this (monkey patch, taken from Ruby's Faraday - include the same param multiple times)
Or use the pre-release 0.9 version of faraday
and add this to your code:
Which will stop it from adding the
[]
symbols.