Expand on params_encoder documentation

This commit is contained in:
Mislav Marohnić 2015-10-02 18:19:02 +02:00
parent ad52344e63
commit a921a30f8b

View File

@ -68,16 +68,28 @@ response = Faraday.get 'http://sushi.com/nigiri/sake.json'
Sometimes you need to send the same URL parameter multiple times with different
values. This requires manually setting the parameter encoder and can be done on
a per-connection basis.
either per-connection or per-request basis.
```ruby
conn.options.params_encoder = Faraday::FlatParamsEncoder
# per-connection setting
conn = Faraday.new :params_encoder => Faraday::FlatParamsEncoder
conn.get do |req|
# per-request setting:
# req.options.params_encoder = my_encoder
req.params['roll'] = ['california', 'philadelphia']
end
# GET 'http://sushi.com?roll=california&roll=philadelphia'
```
The value of Faraday `params_encoder` can be any object that responds to:
* `encode(hash) #=> String`
* `decode(string) #=> Hash`
The encoder will affect both how query strings are processed and how POST bodies
get serialized. The default encoder is Faraday::NestedParamsEncoder.
## Advanced middleware usage
The order in which middleware is stacked is important. Like with Rack, the