logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Data::HAL - Hypertext Application Language resource

Author

       Lars DXXXXXX "<daxim@cpan.org>"

Bugs And Limitations

       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>.

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

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

   Data::HAL::URI::NamespaceMapisundocumented
       It is used only internally.

Configuration And Environment

       Requires no configuration files or environment variables.

Dependencies

       See meta file in the source distribution.

Description

       HAL is a format you can use in your hypermedia API.

   Introduction
       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.

   Conformance
       The author claims to conform with <http://tools.ietf.org/html/draft-kelly-json-hal-06>, published
       2013-10-03.

Diagnostics

"notaJSONobject"
       The "from_json" constructor throws this exception of type "failure::Data::HAL::InvalidJSON" when the JSON
       input is a malformed HAL+JSON document.

Incompatibilities

       None reported.

Interface

Composition
       None.

   Constructors"from_json"

           Data::HAL->from_json($json_str)

       Takes a HAL+JSON document as string and returns a "Data::HAL" object.

       "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.

   Attributes"embedded"

       Type "ArrayRef[Data::HAL]", embedded resource objects <http://tools.ietf.org/html/draft-kelly-json-
       hal#section-4.1.2>

       "links"

       Type "ArrayRef[Data::HAL::Link]", link objects <http://tools.ietf.org/html/draft-kelly-json-
       hal#section-4.1.1>

       "resource"

       Type "HashRef", member data representing the current state of the resource
       <http://tools.ietf.org/html/draft-kelly-json-hal#section-4>

       "relation"

       Type Data::HAL::URI, identifier of the semantics of a link <http://tools.ietf.org/html/rfc5988#section-4>

       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.

   Methods"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.

       "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.

       "Content-Type"

       The value is "application/hal+json", perhaps with a "profile" parameter.

       "Link"

       See "as_http_link_value" in Data::HAL::Link.

   Exports
       None.

Name

       Data::HAL - Hypertext Application Language resource

See Also

       AtomPub <http://enwp.org/AtomPub>, the more mature, featureful hypermedia protocol

Synopsis

           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"'
               # )
           }

To Do

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

Version

       This document describes Data::HAL version 1.001

See Also