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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With