url_join
Join URL path segments and normalize the result.
A simple and clean library for combining URL segments into a properly formatted URL. Handles protocols, slashes, query parameters, and hash fragments automatically.
Example
import url_join
let url = url_join.join([
"https://example.com",
"api",
"v1",
"users",
"?page=1",
])
// -> "https://example.com/api/v1/users?page=1"
Values
pub fn join(parts: List(String)) -> String
Join URL path segments and normalize the result.
This function takes a list of URL segments and combines them into a single, properly normalized URL. It handles protocols, slashes, query strings, and hash fragments intelligently.
Examples
join(["http://www.google.com", "a", "/b/cd", "?foo=123"])
// -> "http://www.google.com/a/b/cd?foo=123"
join(["https://example.com/", "/api/", "users"])
// -> "https://example.com/api/users"
join(["a", "b", "c"])
// -> "a/b/c"
Behaviour
- Filters out empty segments
- Merges a leading bare protocol (e.g.
"http:") with the next segment - Merges a leading
"/"with the next segment - Normalises protocols to
protocol://(andfile:///for file) - Trims and collapses slashes between segments
- Does not add a slash before
?,#, or& - Normalises query string (multiple
?/&become a single?then&)