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 }
userUrl = root </> s "users" </> int .id
userUrl @ { id = 42 } == "/users/42"A parameteried segment of a URL.
The root URL.
root |> toString () == "/"Append a segment to the URL.
An unparameterized (static) segment.
root |> append (s "users") |> toString () == "/users"A parameterized (variable) integer segment.
root
|> append (s "users")
|> append (int .id)
|> toString { id = 42 }
== "/users/42"A parameterized string segment.
root
|> append (s "say")
|> append (string .word)
|> toString { word = "Hello" }
== "/say/Hello"Build a custom segment.
root
|> append (custom (.ids >> List.map fromInt >> String.join ";"))
|> toString { ids = [1, 2, 3] }
== "/1;2;3"Infix version of append.
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 parameterizedSegment.