From a921a30f8bc3482e3cf983ef15547efeb59c6c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 2 Oct 2015 18:19:02 +0200 Subject: [PATCH] Expand on params_encoder documentation --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c52401c..a681a3a1 100644 --- a/README.md +++ b/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