PHP code example of ekino / hal-client

1. Go to this page and download the library: Download ekino/hal-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ekino / hal-client example snippets





// 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');
}



$serializer = Ekino\HalClient\Deserialization\Builder::build();

$object = $serializer->deserialize($resource, 'Acme\Article', 'hal');

bash
php composer.phar