This is a library for creating documents in the application/hal+json and application/hal+xml hypermedia formats
It requires PHP 5.5 or later.
<?php
use Hal;
$hal = new Hal\Resource('/orders');
$hal->addLink('next', '/orders?page=2');
$hal->addLink('search', '/orders?id={order_id}');
$resource = new Hal\Resource(
'/orders/123',
]
'total' => 30.00,
'currency' => 'USD',
]
);
$resource->addLink('customer', '/customer/bob', ['title' => 'Bob Jones <[email protected]>']);
$hal->addResource('order', $resource);
This is still under consideration. There seems to be a few different ways with pros/cons to each
// Method 1
$renderer = new Hal\Renderer\Json;
echo $renderer->render($hal);
// Method 2
echo new Hal\Render\Json()->render($hal);
Hal is provided as a PHP c extension. Go into the ext directory and run the install script. This essentially runs the commands below which will install a hal.so in your php extensions directory.
phpize --silent
./configure --silent --enable-hal
make --silent && make --silent install
Hal is licensed under the MIT license.