rmiller / hal-guzzle-response
Adds Hal resources to Guzzle Responses
0.4.0
2015-09-10 09:36 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle: ~5.0
- nocarrier/hal: ~0.9
Requires (Dev)
- phpspec/phpspec: ~2.1@dev
- rmiller/exemplify-extension: ~0.2
- rmiller/phpspec-run-extension: ~0.1
This package is not auto-updated.
Last update: 2024-12-21 17:07:04 UTC
README
Guzzle event subscriber to decorate responses to provide Hal resources.
If you register the listener it will decorate the responses from Guzzle
giving them a hal
method. This will return a Nocarrier\Hal
resource created from the response body.
Installation
Require the extension:
$ composer require rmiller/hal-guzzle-response:~0.1
Usage
Attach the listener:
$client = new \GuzzleHttp\Client(); $emitter = $client->getEmitter(); $subscriber = new \RMiller\HalGuzzleResponse\GuzzleSubscriber(); $emitter->attach($subscriber);
Get the Hal resource from the response:
$response = $client->get($url); $hal = $response->hal(); //\Nocarrier\Hal
Note: an attempt will be made to convert the response body from JSON and XML to a Hal resource.
If neither is successful a \RuntimeException
will be thrown. This happens when hal
is called,
so it is safe to wrap other responses and not call hal
.