Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Joining URI parts in Elixir

Elixir 1.3 introduced a standard way to join URIs.

For example, say we have a base URI for an API: and different endpoints on that URI: events, developers, applications.

To join the URI into one properly formatted string:

def endpoint_uri(endpoint) do
  |> URI.merge(endpoint)
  |> URI.to_string()

# then call it

endpoint_url("events") # => ""

URI.merge accepts both strings and URI structs as the first object so you can easily continue adding URI parts to the pipeline including query params:

|> URI.merge("events") 
|> URI.merge("?date=today") 
|> URI.to_string()

# => ""
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.