Hateoas
Hateoas copied to clipboard
[RFC] HAL implementation of "curies" link for PaginatedRepresentation
Have "curies" link on PaginetedRepresentation like this
{
"page": 1,
"limit": 20,
"pages": 1,
"total": 1,
"_links": {
"self": {
"href": "/app_dev.php/api/foo/1/bar?page=1&limit=20"
},
"first": {
"href": "/app_dev.php/api/foo/1/bar?page=1&limit=20"
},
"last": {
"href": "/app_dev.php/api/foo/1/bar?page=1&limit=20"
},
"curies": [
{
"href": "/api/foo/{foo}/bar",
"name": "api_get_foo_bar",
"templated": "true"
}
]
},
"_embedded": {
"items": [
{
"id": 2,
"title": "test",
"_links": {
"self": {
"href": "/app_dev.php/api/bar/2"
}
}
}
]
}
}
For the moment i have implemented with annotation like this
<?php
namespace Instable\PhotoBundle\Representation;
use Hateoas\Representation\PaginatedRepresentation;
use Hateoas\Configuration\Annotation as Hateoas;
/**
* Class PaginatedRepresentationWithCuries
*
* @Hateoas\Relation(
* "curies",
* attributes = {
* "name" = "expr(object.getRoute())",
* "templated" = "true"
* },
* href = "expr(service('router').getRouteCollection().get(object.getRoute()).getPath())",
* exclusion = @Hateoas\Exclusion(
* excludeIf = "expr(object.getRoute() === null)"
* )
* )
*/
class PaginatedRepresentationWithCuries extends PaginatedRepresentation
{
}
Its an RFC because i don't know if it's the best way to implement it. (Don't know about efficiency of "expr(service('router'))")
An another way to implement it is to have the Symfony\Component\Routing::$path in Hateoas\Configuration\Route and pass it to the Hateoas\Representation\PaginatedRepresentation::__construct() but this constructor already have 10 arguments
@instabledesign Have you solved your problem? Any follow-ups? I created a CurieExtension (ConfigurationExtensionInterface) that does more-or-less what you described.
Hi, ~~I dont remember because this issue was old. But i think i was solved in a different way.~~
I just re read and the answer was in the question :) I extend PaginatedRepresentation to add annotation and used expression language to do the job...
thanks