So, I'm trying to implement HATEOAS in my application.
On Wisdom level, this more or less mean being able to add "_links"
sub-elements to returned JSON values. This _links element should
contains mappings between action names and their URLs. As an example, i
would like to have, on a portal list
{
[
{"name":"first",
"id":"first",
"links":{
"delete":"
http://localhost/portals/delete/first",
"administrators":"
http://localhost/portals/administrators/first"
}
}
]
}
To emit that, my preferred way would be to annotate my controller
methods. As an example, i would like to simply have to annotate the
removePortal method (which is used to delete) the following way
@Route(method = HttpMethod.GET, uri = Urls.REMOVE_PORTAL)
@HATEOAS(type=Portal.class, id="delete")
@Authenticated(OpenAMAuthenticator.NAME)
public Result removePortal(@Parameter("portal") String portal,
@HttpParameter OpenAMUser user) {
Considering these two requirements, I'm thinkg about modifying the
Result class, in order to make the following things
1 - when JSON result is expected, check what is the content of the result.
2 - If content is an object, scan which controller method have the
HATEOS annotation set with type compatible with given value (obviously,
I should handle the collections as container, and parse their content)
3 - For each found controller, evaluate the route of that method after
having transformed my object into JSON. in other words, replace the
various {} tokens with values pulled from the JsonNode
4 - Then, add the evaluated value in the links element, with id set
according to @HATEOS annotation (or default to method name)
What do you think ?
i've seen that Clement would favor an interceptor. I've already think
about it, but dismissed because i thought it would be harder to get
object type information in order to reconstruct meaningfull information.
However, i think it could be valid if I moved the @HATEOS annotation not
on usable controller methods, but on the controller method used to
return the value. In fact, as of today, I don't really know which
solution would be the best ...