Tesla.Middleware.FormUrlencoded (tesla v1.5.0) View Source
Send request body as application/x-www-form-urlencoded
.
Performs encoding of body
from a Map
such as %{"foo" => "bar"}
into
url encoded data.
Performs decoding of the response into a map when urlencoded and content-type
is application/x-www-form-urlencoded
, so "foo=bar"
becomes
%{"foo" => "bar"}
.
Examples
defmodule Myclient do
use Tesla
plug Tesla.Middleware.FormUrlencoded
end
Myclient.post("/url", %{key: :value})
Options
:decode
- decoding function, defaults toURI.decode_query/1
:encode
- encoding function, defaults toURI.encode_query/1
Nested Maps
Natively, nested maps are not supported in the body, so
%{"foo" => %{"bar" => "baz"}}
won't be encoded and raise an error.
Support for this specific case is obtained by configuring the middleware to
encode (and decode) with Plug.Conn.Query
defmodule Myclient do
use Tesla
plug Tesla.Middleware.FormUrlencoded,
encode: &Plug.Conn.Query.encode/1,
decode: &Plug.Conn.Query.decode/1
end
Myclient.post("/url", %{key: %{nested: "value"}})
Link to this section Summary
Link to this section Functions
Decode response body as querystring.
It is used by Tesla.Middleware.DecodeFormUrlencoded
.
Encode response body as querystring.
It is used by Tesla.Middleware.EncodeFormUrlencoded
.