HATEOAS principal in retrofit? link to resources?
Asked Answered
I

1

6

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?

Iolite answered 18/5, 2015 at 8:25 Comment(2)
you can check out my HATEOAS with Retrofit code here: stackoverflow.com/questions/33404734Homopolar
From 2013: github.com/square/retrofit/issues/333#issue-20454355Garb
P
0

Retrofit 2 has the @Url annotation for that.

Example:

public interface TempoRestApi {
    @GET("worklogs/issue/{issueKey}")
    Call<IssueWorklogResponse> getIssueWorklog(@Path("issueKey") String issueKey, @Query("from") String date, @Query("to") String end);

    @GET
    Call<IssueWorklogResponse> getIssueWorklog(@Url String url);
}

The first method is a normal retrofit @GET call. The response of that one has metadata that gives an absolute URL to the next page of results:

"metadata": {
    "count": 50,
    "offset": 0,
    "limit": 50,
    "next": "https://api.tempo.io/core/3/worklogs/issue/KEY-1?from=2020-01-01&to=2020-12-31&offset=50&limit=50"
  }

The 2nd one can be used with the returned next link that the first call gives.

Perforation answered 14/10, 2020 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.