Url.Builder
HTML & web
Build absolute, relative, and cross-origin URLs with query parameters.
Path segments are joined as-is; query keys and values are percent-encoded via Url.percentEncode.
Types
Root
type Root
= Absolute
| Relative
| CrossOrigin StringWhether a custom URL is absolute, relative, or cross-origin.
Examples
Absolute
Relative
CrossOrigin "https://cdn.example.com"QueryParameter
type QueryParameter = QueryParameter String StringA percent-encoded query parameter.
Examples
string "q" "a b"Values
absolute
absolute : List String -> List QueryParameter -> StringCreate an absolute URL (always starts with /).
Examples
absolute [] []
== "/"
absolute [ "products" ] [ string "search" "hat", int "page" 2 ]
== "/products?search=hat&page=2"relative
relative : List String -> List QueryParameter -> StringCreate a relative URL (no leading slash).
Examples
relative [] []
== ""
relative [ "products" ] [ string "search" "hat" ]
== "products?search=hat"crossOrigin
crossOrigin : String -> List String -> List QueryParameter -> StringCreate a cross-origin URL from a pre-path (scheme + host + optional port).
Examples
crossOrigin "https://example.com" [ "products" ] []
== "https://example.com/products"custom
custom : Root -> List String -> List QueryParameter -> Maybe String -> StringBuild a URL that may include a fragment.
Examples
custom Absolute [ "docs", "stdlib" ] [] (Just "Time")
== "/docs/stdlib#Time"string
string : String -> String -> QueryParameterCreate a percent-encoded string query parameter.
Examples
string "search" "a b"int
int : String -> Int -> QueryParameterCreate a query parameter from an integer key name and value.
Examples
int "page" 2toQuery
toQuery : List QueryParameter -> StringConvert query parameters to a ?... suffix, or "" if empty.
Examples
toQuery [] == ""
toQuery [ string "q" "hi" ] == "?q=hi"