form_coder

x-www-form-urlencoded codec

The codec follows the WHATWG specification available at: https://url.spec.whatwg.org/#application/x-www-form-urlencoded but uses UTF-8 as the only supported encoding.

Types

pub type DecodeError {
  InvalidQuery
  DynamicError(List(dynamic.DecodeError))
}

Constructors

  • InvalidQuery
  • DynamicError(List(dynamic.DecodeError))
pub type Query {
  QStr(String)
  QList(List(Query))
  QMap(Map(String, Query))
}

Constructors

  • QStr(String)
  • QList(List(Query))
  • QMap(Map(String, Query))

Functions

pub fn decode(from encoded: String, using decoder: fn(Dynamic) ->
    Result(a, List(DecodeError))) -> Result(
  a,
  form_coder.DecodeError,
)

Decode the URL query string into a data structure as specified by decoder (likely a function from gleam/dynamic).

pub fn encode(contents: List(#(String, Query))) -> String

Encode a list of pairs into a URL query string

The values of these pairs should be of the Query type.

Examples

> encode([#("foo", QStr("bar bar")), #("baz", QStr("qux"))])
"foo=bar+bar&baz=qux"

> encode([#("foo", QList([QStr("bar"), QStr("b!z")]))])
"foo%5B%5D=bar&foo%5B%5D=b%21z"

> encode([#("foo", QMap(map.from_list([#("bar", "baz")])))])
"foo%5Bbar%5D=baz"
Search Document