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
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.
Deprecated
See to_json_map/1
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
t()
t() :: %ExHal.Link{
href: String.t(),
name: String.t(),
rel: String.t(),
target: ExHal.Document.t(),
templated: boolean()
}
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
embedded?(link)
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!()
embedded_link(bindings) (macro)
Expands the embedded_link pattern.
See embedded_link/0.
embedded_link!()
(macro)
embedded_link!() :: any()
embedded_link!() :: any()
Builds data using the embedded_link pattern.
See embedded_link/0.
equal?(link_a, link_b)
equal?(ExHal.Link.t(), ExHal.Link.t()) :: boolean()
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
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
from_embedded(rel, embedded_doc)
Build new link struct from embedded doc.
from_links_entry(rel, a_map)
Build new link struct from _links entry.
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!()
simple_link(bindings) (macro)
Expands the simple_link pattern.
See simple_link/0.
simple_link!()
(macro)
simple_link!() :: any()
simple_link!() :: any()
Builds data using the simple_link pattern.
See simple_link/0.
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
target_url!(a_link, vars \\ %{})
Returns target url, expanded with vars if any are provided.
Returns "fully_qualified_url" or raises exception
to_json_hash(link)
Deprecated
See to_json_map/1
to_json_map(link)
Returns a map that matches the shape of the intended JSON output.
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!()
unnamed_link(bindings) (macro)
Expands the unnamed_link pattern.
See unnamed_link/0.
unnamed_link!()
(macro)
unnamed_link!() :: any()
unnamed_link!() :: any()
Builds data using the unnamed_link pattern.
See unnamed_link/0.