Joining URIs

Hey all, I’m looking for something similar to the Ruby Addressable gem, to join URLs.

That is, given a base URL and a relative URL, it will join them to return the absolute URL, like:

> Addressable::URI.join("http://example.com/faqs.html", "../contact").to_s
 => "http://example.com/contact"

I suppose this should be done using URI and Path, but there are many cases to consider and I wonder if there is already a package that handles this.

Thanks!

2 Likes

This will be available in Elixir 1.3 as URI.merge/2:

iex> URI.merge("http://example.com/faqs.html", "../contact") |> URI.to_string()
"http://example.com/contact"
7 Likes

That’s great news, thanks! :slight_smile:

1 Like