Data::HAL - Hypertext Application Language resource
This document describes Data::HAL version 1.000
use Data::HAL qw(); use Data::HAL::Link qw(); { my $hal = Data::HAL->from_json($json_str); my $resource_member_data_href = $hal->resource; my $links_aref = $hal->links; my $embedded_resources_aref = $hal->embedded; } { my $hal = Data::HAL->new( resource => {foo => 23, bar => 42}, links => [Data::HAL::Link->new(relation => 'self', href => '/')], ); my $json_str = $hal->as_json; # { # "_links" : { # "self" : { # "href" : "/" # } # }, # "bar" : 42, # "foo" : 23 # } my @headers = $hal->http_headers; # ( # 'Content-Type' => 'application/hal+json', # 'Link' => '</>;rel="self"' # ) }
HAL is a format you can use in your hypermedia API.
This section is completely quoted from the specification:
There is an emergence of non-HTML HTTP applications ("Web APIs") which use hyperlinks to direct clients around their resources.
The JSON Hypertext Application Language (HAL) is a standard which establishes conventions for expressing hypermedia controls, such as links, with JSON.
HAL is a generic media type with which Web APIs can be developed and exposed as series of links. Clients of these APIs can select links by their link relation type and traverse them in order to progress through the application.
HAL's conventions result in a uniform interface for serving and consuming hypermedia, enabling the creation of general-purpose libraries that can be re-used on any API utilising HAL.
The primary design goals of HAL are generality and simplicity. HAL can be applied to many different domains, and imposes the minimal amount of structure necessary to cover the key requirements of a hypermedia Web API.
The author claims to conform with http://tools.ietf.org/html/draft-kelly-json-hal-06, published 2013-10-03.
None.
from_json
Data::HAL->from_json($json_str)
Takes a HAL+JSON document as string and returns a Data::HAL object.
Data::HAL
new
Data::HAL->new( resource => {foo => 23, bar => 42}, links => [Data::HAL::Link->new(relation => 'self', href => '/')] )
Default Moo constructor, returns a Data::HAL object.
embedded
Type ArrayRef[Data::HAL], embedded resource objects
ArrayRef[Data::HAL]
links
Type ArrayRef[Data::HAL::Link], link objects
ArrayRef[Data::HAL::Link]
resource
Type HashRef, member data representing the current state of the resource
HashRef
relation
Type Data::HAL::URI, identifier of the semantics of a link
Perl strings are coerced to the Data::HAL::URI type.
A stand-alone HAL+JSON document, when deserialised, will not have this attribute set in the root resource since nothing is linking to the document.
TO_JSON
Serialisation hook for the JSON (or compatible) module.
This method is not intended to be called directly from your code. Instead call "as_json" or JSON::to_json $hal, { convert_blessed => 1 } or similar.
JSON::to_json $hal, { convert_blessed => 1 }
as_json
Returns the resource object serialised as a HAL+JSON document string.
http_headers
Returns a list of pairs of HTTP message headers. The keys are field name strings and the values are field content strings. Warning: since field names can repeat, assigning this list to a hash loses information.
The list is suitable as input for e.g. the headers accessor in HTTP::Headers or the headers attribute in Plack::Response.
headers
Content-Type
The value is application/hal+json, perhaps with a profile parameter.
application/hal+json
profile
Link
See "as_http_link_value" in Data::HAL::Link.
not a JSON object
The "from_json" constructor throws this exception of type failure::Data::HAL::InvalidJSON when the JSON input is a malformed HAL+JSON document.
failure::Data::HAL::InvalidJSON
Requires no configuration files or environment variables.
See meta file in the source distribution.
None reported.
Please report any bugs or feature requests to bug-data-hal@rt.cpan.org, or through the web interface at https://rt.cpan.org/Public/Dist/Display.html?Name=Data-HAL.
bug-data-hal@rt.cpan.org
It is currently difficult to exert control over the specifics of (de)serialisation, perhaps put the (de)serialisers into attributes?
It is not worth it to design an error class hierarchy for a single error.
It is used only internally.
AtomPub, the more mature, featureful hypermedia protocol
Lars Dɪᴇᴄᴋᴏᴡ <daxim@cpan.org>
<daxim@cpan.org>
Copyright © 2013 Lars Dɪᴇᴄᴋᴏᴡ <daxim@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.18.0.
This library is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Data::HAL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::HAL
CPAN shell
perl -MCPAN -e shell install Data::HAL
For more information on module installation, please visit the detailed CPAN module installation guide.