This is more of a bookmark post. But Ive been looking at some RESTful API’s recently and trying to decide the best approach – which was most likely Springs REST template. I then found RetrofitRetrofit as an alternative.
Its syntax is pretty simple, and it basically maps the JSON response to the Java object, and all you are required to do is define the interface. Similar to Spring Data.
The example given on the retrofit website demonstrates this –
public interface GitHubService {
@GET("/users/{user}/repos")
List listRepos(@Path("user") String user);
}
Then to call the code –
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.github.com")
.build();
GitHubService service = restAdapter.create(GitHubService.class);
List repos = service.listRepos("octocat");
I’ll definitely consider this in future projects
Like this:
Like Loading...