Man pages sections > man3 > Data::HAL

Data::HAL - Hypertext Application Language resource

Data::HAL(3pm) User Contributed Perl Documentation Data::HAL(3pm)


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 <>, published 2013-10-03.





Takes a HAL+JSON document as string and returns a "Data::HAL" object.
        resource => {foo => 23, bar => 42},
        links    => [Data::HAL::Link->new(relation => 'self', href => '/')]
Default Moo constructor, returns a "Data::HAL" object.


Type "ArrayRef[Data::HAL]", embedded resource objects <>
Type "ArrayRef[Data::HAL::Link]", link objects <>
Type "HashRef", member data representing the current state of the resource <>
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.


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.
Returns the resource object serialised as a HAL+JSON document string.
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.
The value is "application/hal+json", perhaps with a "profile" parameter.
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.


Requires no configuration files or environment variables.


See meta file in the source distribution.


None reported.


Please report any bugs or feature requests to "", or through the web interface at <>.

tight coupling to JSON

It is currently difficult to exert control over the specifics of (de)serialisation, perhaps put the (de)serialisers into attributes?

error type is an attribute, not a class name

It is not worth it to design an error class hierarchy for a single error.

Data::HAL::URI::NamespaceMap is undocumented

It is used only internally.


make everything cache-friendly
non-standard accessors for link objects
support X8.3. cache pattern
support HAL XML


AtomPub <>, the more mature, featureful hypermedia protocol


Lars DXXXXXX "<>" Copyright X 2013 Lars DXXXXXX "<>"
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.18.0.

Disclaimer of warranty

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.
2015-12-25 perl v5.22.1