Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Last active Aug 29, 2015
Embed
What would you like to do?
defmodule QueryUtil do
def add_params_to_url(url, params) do
url <> query_string(params)
end
defp query_string(params) do
params |> Enum.map(&("#{&1.name}=#{&1.value}")) |> Enum.join("&")
end
end
url = "http://example.com?"
params = [
%{name: "test1", value: "value1"},
%{name: "test2", value: "value2"}
]
result = QueryUtil.add_params_to_url(url, params)
IO.puts "result: #{inspect result}"
# ➜ ~ elixir query_util.exs
# result: "http://example.com?test1=value1&test2=value2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment