URI.decode_query
decode_query
, go back to URI module for more information.
Specs
decode_query(binary(), %{optional(binary()) => binary()}, :rfc3986 | :www_form) :: %{optional(binary()) => binary()}
Decodes query
into a map.
Given a query string in the form of key1=value1&key2=value2...
, this
function inserts each key-value pair in the query string as one entry in the
given map
. Keys and values in the resulting map will be binaries. Keys and
values will be percent-unescaped.
You can specify one of the following encoding
options:
:www_form
- (default, since v1.12.0) keys and values are decoded as perdecode_www_form/1
. This is the format typically used by browsers on query strings and form data. It decodes "+" as " ".:rfc3986
- (since v1.12.0) keys and values are decoded as perdecode/1
. The result is the same as:www_form
except for leaving "+" as is in line with RFC 3986.
Encoding defaults to :www_form
for backward compatibility.
Use query_decoder/1
if you want to iterate over each value manually.
Examples
iex> URI.decode_query("foo=1&bar=2")
%{"bar" => "2", "foo" => "1"}
iex> URI.decode_query("percent=oh+yes%21", %{"starting" => "map"})
%{"percent" => "oh yes!", "starting" => "map"}
iex> URI.decode_query("percent=oh+yes%21", %{}, :rfc3986)
%{"percent" => "oh+yes!"}