URL.UUID (URL v2.0.3)

Copy Markdown View Source

Parses the scheme-specific part of a uuid URL as described in draft-kindel-uuid-uri, and the urn:uuid: form of the same identifier.

The primary API is parse/1, which URL.new/1 calls for any URL with the uuid or urn scheme. A urn whose namespace is not uuid is accepted but yields no parsed path.

Summary

Functions

Parses the path of a uuid or urn URI into a t/0 struct.

Types

t()

@type t() :: %URL.UUID{params: map(), uuid: binary()}

Functions

parse(uri)

@spec parse(URI.t()) :: {:ok, t()} | {:error, {module(), binary()}}

Parses the path of a uuid or urn URI into a t/0 struct.

Arguments

  • uri is a URI.t/0 whose :scheme is "uuid" or "urn".

Returns

  • {:ok, t:t/0} with the UUID and any parameters, or

  • {:ok, nil} for a urn whose namespace is not uuid, or

  • {:error, {URL.Parser.ParseError, reason}} if the path is not a valid UUID, or the urn has no namespace identifier.

Examples

iex> uuid = URI.parse("uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6;a=b")
iex> URL.UUID.parse(uuid)
{:ok,
 %URL.UUID{uuid: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", params: %{"a" => "b"}}}

iex> uuid = URI.parse("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6;a=b")
iex> URL.UUID.parse(uuid)
{:ok, %URL.UUID{params: %{"a" => "b"}, uuid: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"}}

iex> URL.UUID.parse(URI.parse("urn:isbn:0451450523"))
{:ok, nil}

iex> {:error, {URL.Parser.ParseError, _reason}} = URL.UUID.parse(URI.parse("uuid:not-a-uuid"))