View Source Tesla.Middleware.FormUrlencoded (tesla v1.13.0)

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

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"}})

Summary

Functions

Decode response body as querystring.

Encode response body as querystring.

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.