I am analyzing retrofit on android and had a question on callbacks vs not using them. I am under the impression that callbacks are only used for success and failure responses a client might desire. Otherwise i would omit it. Here is an example of a retrofit interface without a callback:
public interface GitHubService {
@GET("/users/{user}/repos")
List<Repo> listRepos(@Path("user") String user);
}
and here is an example with a callback (i hope i have it right):
public interface GitHubService {
@GET("/users/{user}/repos")
List<Repo> listRepos(@Path("user") String user,Callback<Repo> cb);
}
Im confused on two things:
The return value in the interface is List but to me it should be void because retrofit will use gson to convert the json response to a Repo POJO. All i have to do is create the Repo POJO so i would expect the last piece of code to be like this instead:
public interface GitHubService {
@GET("/users/{user}/repos")
void listRepos(@Path("user") String user,Callback cb); }
What is the purpose of the return value?
- my second question is : is the callback only necessary to know if the request was a success or failure as i see from the docs that callback has two methods: failure and success.