Uniform Resource Name (URN) parsing and validation in Elixir
Add urn
to your list of dependencies in mix.exs
:
def deps do
[{:urn, "~> 1.0.0"}]
end
defmodule Project do
alias URN
def action() do
# Parse input string "urn:collection:id" to Map
{:ok, urn} = URN.parse("urn:collection:id")
IO.inspect urn
# %URN{fragment: nil, nid: "collection", nss: "id", query: nil, resolution: nil}
# Turn back into a string
URN.to_string(urn)
# urn:collection:id
end
end
License MIT