form_coder

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, 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")), #("baz", QStr("qux"))])
"foo=bar&baz=qux"

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

> encode([#("foo", QMap(map.from_list([#("bar", "baz")])))])
"foo[bar]=baz"