HalClient is a lightweight library to consume HAL resources.
Add the dependency:
php composer.phar require ekino/hal-client
If asked for a version, type in 'dev-master' (unless you want another version):
Please provide a version constraint for the ekino/hal-client requirement: dev-master
There is no support for POST/PUT/PATCH/DELETE methods.
<?php
// create a HttpClient to perform http request
$client = new FileGetContentsHttpClient('http://propilex.herokuapp.com', array(
'Authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
));
// create an entry point to retrieve the data
$entryPoint = new EntryPoint('/', $client);
$resource = $entryPoint->get(); // return the main resource
// retrieve a Resource object, which acts as a Pager
$pager = $resource->get('p:documents');
$pager->get('page');
$collection = $pager->get('documents'); // return a ResourceCollection
// a ResourceCollection implements the \Iterator and \Countable interface
foreach ($collection as $document) {
// the document is a resource object
$document->get('title');
}
The library support deserialization of Resource object into native PHP object.
$serializer = Ekino\HalClient\Deserialization\Builder::build();
$object = $serializer->deserialize($resource, 'Acme\Article', 'hal');