-
-
Save TrevorS/eedbb1e109b6c02d78ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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