Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HATEOAS principal in retrofit? link to resources?

How can I use the HATEOAS principal in retrofit? Is there any way to use links in retrofit? Or should I parse it on my own?

links: [4]
0:  {
rel: "self"
href: "https://localhost/api/product/9"
}-
1:  {
rel: "comp"
href: "https://localhost/api/product/19/comp"
}-
2:  {
rel: "eval"
href: "https://localhost/api/product/19/eval"
}

My general question is, how can I use links to resource (http://en.wikipedia.org/wiki/HATEOAS)? Is there any possibility? For example how can i invoke the "comp" href to the resource and get i parsed Java-Object (from JSON) return?

like image 829
E.P Avatar asked May 18 '15 08:05

E.P


1 Answers

Retrofit works great and probably has the cleanest API as far as rest clients goes in the java world. The one limitation is that it's really hard to use to follow links. I understand that it probably wasn't a design goal but would it be something you'd consider? I could easily call the URL directly but I really want to be able to use the error handling, logging, converters and everything else configured in the RestAdapter.

Currently you can do:

@GET("/{path}")
SomeObject get(@EncodedPath("path") String path);

It works well but this means you can only follow links going to the server configured with the RestAdapter. What do you think about adding a @Url annotation?

@GET 
SomeObject get(@Url String url);

@POST
void post(@Url String url, @Body SomeObject object);
like image 95
Umer Kiani Avatar answered Sep 22 '22 12:09

Umer Kiani