Download the PHP package mixerapi/hal-view without Composer
On this page you can find all versions of the php package mixerapi/hal-view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mixerapi/hal-view
More information about mixerapi/hal-view
Files in mixerapi/hal-view
Package hal-view
Short Description A Hypertext Application Language (HAL+JSON) view for CakePHP.
License MIT
Informations about the package hal-view
MixerApi HAL View
A Hypertext Application Language (HAL+JSON) View for CakePHP. This plugin
supports links, pagination, and embedded resources. Once setup any request with application/hal+json
will be
rendered by this plugin.
Table of Contents
- Installation
- Setup
- Usage
- Serializing
Installation
!!! note "" You can skip this step if MixerAPI is installed.
Alternatively after composer installing you can manually load the plugin in your Application:
Setup
Your controllers must be using the RequestHandler
component. This is typically loaded in your AppController
.
Usage
For _link.self.href
support you will need to implement MixerApi\HalView\HalResourceInterface
on entities that you
want to expose as HAL resources. This informs the plugin that the Entity should be treated as a HAL resource and
provides the mapper with a _link.self.href
URL:
Now an HTTP GET to the /actors/149
endpoint will render HAL using the CakePHP native serialization process:
Example
If your Entity does not implement the interface it will still be returned as HAL resource when serialized, but minus
the _links
property. Collection requests will work without this interface as well, example:
Example
If the Actor and Film entities were implementing MixerApi\HalView\HalResourceInterface
then the example above would
include the _links
property for each serialized entity.
Try it out for yourself:
Serializing
Optionally, you can manually serialize data into HAL using JsonSerializer
. This is the same class that the main HalJsonView uses. Example: