Merge branch 'params-docs'

Closes #491, references #182

[ci skip]
This commit is contained in:
Mislav Marohnić 2015-10-02 18:20:00 +02:00
commit e11151ded9

View File

@ -65,6 +65,32 @@ stack and default adapter (see [Faraday::RackBuilder#initialize](https://github.
response = Faraday.get 'http://sushi.com/nigiri/sake.json'
```
### Changing how parameters are serialized
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
either per-connection or per-request basis.
```ruby
# 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