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.
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