exhal v8.2.0 ExHal.Interpreter
Helps to build interpters of HAL documents.
Given a document like
{
"name": "Jane Doe",
"mailingAddress": "123 Main St",
"_links": {
"app:department": { "href": "http://example.com/dept/42" }
}
}
We can define an interpreter for it.
defmodule PersonInterpreter do
use ExHal.Interpreter
defextract :name
defextract :address, from: "mailingAddress"
defextractlink :department_url, rel: "app:department"
end
We can use this interpreter to to extract the pertinent parts of the document into a map.
iex> PersonInterpreter.to_params(doc)
%{name: "Jane Doe",
address: "123 Main St",
department_url: "http://example.com/dept/42"}
Link to this section Summary
Link to this section Functions
Link to this macro
defextract(name, options \\ []) (macro)
Define a property extractor.
- name - the name of the parameter to extract
options - Keywords of optional arguments
- :from - the name of the property in the JSON document. Default is
to_string(name)
.
- :from - the name of the property in the JSON document. Default is
Link to this macro
defextractlink(name, options \\ []) (macro)
Define a link extractor.
- name - the name of the parameter to extract
options - Keywords of optional arguments
- :rel - the rel or the link in the JSON document. Required.
Link to this function