Installation
Installation
The recommended way to install Hateoas is through
Composer. Require the willdurand/hateoas package
by running the following command:
composer require willdurand/hateoas
This will resolve the latest stable version.
Otherwise, install the library and setup the autoloader yourself.
Working With Symfony2
There is a bundle for that! Install the BazingaHateoasBundle, and enjoy!
Important: For those who use the
1.0version, you can jump to this documentation page as the following documentation has been written for Hateoas 2.0 and above.
Introduction
Hateoas leverages the Serializer library to provide a nice way to build HATEOAS REST web services. HATEOAS stands for Hypermedia as the Engine of Application State, and adds hypermedia links to your representations (i.e. your API responses). HATEOAS is about the discoverability of actions on a resource.
For instance, let's say you have a User API which returns a representation of a single user as follows:
{
"user": {
"id": 123,
"first_name": "John",
"last_name": "Doe"
}
}
In order to tell your API consumers how to retrieve the data for this specific
user, you have to add your very first link to this representation, let's
call it self as it is the URI for this particular user:
{
"user": {
"id": 123,
"first_name": "John",
"last_name": "Doe",
"_links": {
"self": { "href": "http://example.com/api/users/123" }
}
}
}
Let's dig into Hateoas now.