A tiny library for building parameterized URLs. It is intended to be used with records to give the parameters names and therefore reducing errors.
userUrl : Url { id : Int, show : Bool }
userUrl = root </> s "users" </> int .id <?> ("show", bool .show)
userUrl @ { id = 42, show = True } == "/users/42?show=true"A parameterized part (segment or query value) of a URL.
The root URL.
root |> toString () == "/"Append a segment to the URL.
An unparameterized (static) part.
root |> append (s "users") |> toString () == "/users"A parameterized (variable) integer part.
root
|> append (s "users")
|> append (int .id)
|> toString { id = 42 }
== "/users/42"A parameterized string part.
root
|> append (s "say")
|> append (string .word)
|> toString { word = "Hello" }
== "/say/Hello"A parameterized boolean part.
root
|> append (bool .show)
|> toString { show = True }
== "/true"Build a custom part.
root
|> append (custom (.ids >> List.map fromInt >> String.join ";"))
|> toString { ids = [1, 2, 3] }
== "/1;2;3"Append a query parameter to the URL.
root
|> append (s "part")
|> appendParam "show" (bool .show)
|> toString { show = True }
== "/part?show=true"Infix version of append.
Infix version of appendParam
Give a string representation of the URL, given a value for the parameter.
Infix version of toString ("evaluate at").
A URL parameterized over the type
a, which is typically a record containing a field for each parameterizedPart.