Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.03 KB

url_encoded.md

File metadata and controls

42 lines (34 loc) · 1.03 KB
layout title permalink hide prev_name prev_link next_name next_link top_name top_link
documentation
UrlEncoded Middleware
/middleware/url-encoded
true
Multipart Middleware
./multipart
JSON Request Middleware
./json-request
Back to Middleware
./list

The UrlEncoded middleware converts a Faraday::Request#body hash of key/value pairs into a url-encoded request body. The middleware also automatically sets the Content-Type header to application/x-www-form-urlencoded. The way parameters are serialized can be customized.

Example Usage

conn = Faraday.new(...) do |f|
  f.request :url_encoded
  ...
end

conn.post('/', { a: 1, b: 2 })
# POST with
# Content-Type: application/x-www-form-urlencoded
# Body: a=1&b=2

Complex structures can also be passed

conn.post('/', { a: [1, 3], b: { c: 2, d: 4} })
# POST with
# Content-Type: application/x-www-form-urlencoded
# Body: a%5B%5D=1&a%5B%5D=3&b%5Bc%5D=2&b%5Bd%5D=4