exhal v8.2.0 ExHal.Link

A Link is a directed reference from one resource to another resource. They are found in the _links and _embedded sections of a HAL document

Link to this section Summary

Types

t()

A link. Links may be simple or dereferenced (from the embedded section).

Functions

Expands the embedded_link pattern.

Expands the embedded_link pattern.

Builds data using the embedded_link pattern.

Returns true if the links are equivalent.

Expands "curie"d link rels using the namespaces found in the curies link.

Build new link struct from embedded doc.

Build new link struct from _links entry.

Expands the simple_link pattern.

Expands the simple_link pattern.

Builds data using the simple_link pattern.

Returns target url, expanded with vars if any are provided.

Returns target url, expanded with vars if any are provided.

Returns a map that matches the shape of the intended JSON output.

Expands the unnamed_link pattern.

Expands the unnamed_link pattern.

Builds data using the unnamed_link pattern.

Link to this section Types

Link to this type

t()
t() :: %ExHal.Link{
  href: String.t(),
  name: String.t(),
  rel: String.t(),
  target: ExHal.Document.t(),
  templated: boolean()
}

A link. Links may be simple or dereferenced (from the embedded section).

Link to this section Functions

Link to this function

embedded?(link)

Link to this macro

embedded_link() (macro)

Expands the embedded_link pattern.

%{target: %{}}

Binding Variables

The following variables can be bound by giving them to embedded_link as keys on its last argument Keyword.

For example:

embedded_link(: x)

Where x can be any value, variable in your scope or another pattern expansion. Not mentioned variables will be unbound and replaced by an _ at expansion site. Likewise, calling embedded_link() with no argumens will replace all its variables with _.

Positional Variables

embedded_link variables can also be bound by position, provided the last them is not a Keyword.

For example:

embedded_link(, bindings = [])

Bang Constructor

The embedded_link! constructor can be used to build data and make sure the guards are satisfied.

Note that this macro can only be used as an expression and not as a matching pattern.

For example:

embedded_link!()
Link to this macro

embedded_link(bindings) (macro)
embedded_link(bindings :: keyword()) :: any()

Expands the embedded_link pattern.

See embedded_link/0.

Link to this macro

embedded_link!() (macro)
embedded_link!() :: any()

Builds data using the embedded_link pattern.

See embedded_link/0.

Link to this function

equal?(link_a, link_b)
equal?(ExHal.Link.t(), ExHal.Link.t()) :: boolean()

Returns true if the links are equivalent.

Comparison rules:

  • simple links are equal if their hrefs are equal and their names are equal.
  • embedded links are equal if their hrefs are non-nil and equal
  • a simple and an embedded link are equal if their hrefs are equal
Link to this function

expand_curie(link, namespaces)

Expands "curie"d link rels using the namespaces found in the curies link.

Returns [%Link{}, ...] a link struct for each possible variation of the input link

Link to this function

from_embedded(rel, embedded_doc)

Build new link struct from embedded doc.

Link to this macro

simple_link() (macro)

Expands the simple_link pattern.

%{target: nil}

Binding Variables

The following variables can be bound by giving them to simple_link as keys on its last argument Keyword.

For example:

simple_link(: x)

Where x can be any value, variable in your scope or another pattern expansion. Not mentioned variables will be unbound and replaced by an _ at expansion site. Likewise, calling simple_link() with no argumens will replace all its variables with _.

Positional Variables

simple_link variables can also be bound by position, provided the last them is not a Keyword.

For example:

simple_link(, bindings = [])

Bang Constructor

The simple_link! constructor can be used to build data and make sure the guards are satisfied.

Note that this macro can only be used as an expression and not as a matching pattern.

For example:

simple_link!()
Link to this macro

simple_link(bindings) (macro)
simple_link(bindings :: keyword()) :: any()

Expands the simple_link pattern.

See simple_link/0.

Link to this macro

simple_link!() (macro)
simple_link!() :: any()

Builds data using the simple_link pattern.

See simple_link/0.

Link to this function

target_url(a_link, vars \\ %{})

Returns target url, expanded with vars if any are provided.

Returns {:ok, "fully_qualified_url"}

      `:error` if link target is anonymous
Link to this function

target_url!(a_link, vars \\ %{})

Returns target url, expanded with vars if any are provided.

Returns "fully_qualified_url" or raises exception

Link to this function

to_json_hash(link)

Deprecated See to_json_map/1

Link to this function

to_json_map(link)

Returns a map that matches the shape of the intended JSON output.

Link to this macro

unnamed_link() (macro)

Expands the unnamed_link pattern.

%{name: nil}

Binding Variables

The following variables can be bound by giving them to unnamed_link as keys on its last argument Keyword.

For example:

unnamed_link(: x)

Where x can be any value, variable in your scope or another pattern expansion. Not mentioned variables will be unbound and replaced by an _ at expansion site. Likewise, calling unnamed_link() with no argumens will replace all its variables with _.

Positional Variables

unnamed_link variables can also be bound by position, provided the last them is not a Keyword.

For example:

unnamed_link(, bindings = [])

Bang Constructor

The unnamed_link! constructor can be used to build data and make sure the guards are satisfied.

Note that this macro can only be used as an expression and not as a matching pattern.

For example:

unnamed_link!()
Link to this macro

unnamed_link(bindings) (macro)
unnamed_link(bindings :: keyword()) :: any()

Expands the unnamed_link pattern.

See unnamed_link/0.

Link to this macro

unnamed_link!() (macro)
unnamed_link!() :: any()

Builds data using the unnamed_link pattern.

See unnamed_link/0.