mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-09 00:04:39 -04:00
commit
e11151ded9
26
README.md
26
README.md
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user