ekino / hal-client
HalClient
Installs: 11 620
Dependents: 0
Suggesters: 0
Security: 0
Stars: 33
Watchers: 24
Forks: 12
Open Issues: 7
Requires
- php: >=5.4.0
- doctrine/collections: ~1.2
- guzzle/parser: ~3.9
Requires (Dev)
- doctrine/collections: ~1.2
- jms/serializer: ~0.16
Suggests
- jms/serializer: Enable support of Resource Deserialization
This package is auto-updated.
Last update: 2024-02-25 21:37:51 UTC
README
HalClient is a lightweight library to consume HAL resources.
Installation using Composer
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
Limitations
There is no support for POST/PUT/PATCH/DELETE methods.
Usage
<?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'); }
Integrate JMS/Deserializer
The library support deserialization of Resource object into native PHP object.
$serializer = Ekino\HalClient\Deserialization\Builder::build(); $object = $serializer->deserialize($resource, 'Acme\Article', 'hal');