mirror of
https://github.com/lostisland/faraday.git
synced 2025-12-07 00:01:45 -05:00
Expand on params_encoder documentation
This commit is contained in:
parent
ad52344e63
commit
a921a30f8b
16
README.md
16
README.md
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user