I am still experimenting if this is the best way to use this, but here is what I still have. This may not be the cleanest approach, but I like it compared to one service with 100 api calls. Breaks it up a bit and makes reading easier.
This is the main class for accessing data. I saw many separate two static methods that I have in a separate class, but I just included it as one.
public class RetrofitApi { public enum ApiTypes { USER_API(UserApi.class); private final Class<? extends RetrofitApi> apiClass; ApiTypes(Class<? extends RetrofitApi> apiClass){ this.apiClass = apiClass; } Class<? extends RetrofitApi> getApiType() {return this.apiClass;} } public static <T> T getApi(RetrofitApi.ApiTypes type) { try { return (T) type.getApiType().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; } public static RestAdapter getRestAdapter() { RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(BASE_URL) .setLogLevel(retrofit.RestAdapter.LogLevel.HEADERS) .build(); return restAdapter; } }
Each service has its own api. This means more classes. I divided them into api, service, model. An API is a high level that you will use and disclose. A service is more or less just a call list. Model - model (data object).
public class UserApi extends RetrofitApi { private UserService service; public UserApi() { RestAdapter restAdapter = RetrofitApi.getRestAdapter(); service = restAdapter.create(UserService.class); } public void login(String email, String password, Callback<User> callback) { service.login(email, password, callback); } }
Service is an interface. Its more or less just a list of called api calls.
public interface UserService { @GET("/api/users/login") void login(@Query("email") String email, @Query("password") String password, Callback<User> callback); }
Then use it.
UserApi api = RetrofitApi.getApi(RetrofitApi.ApiTypes.USER_API); api.login(email,password,callback);
And here is the structure of the project. For me it seems clean at the moment. I am sure that it will become big when I have 20+ of them. But it can be a little cleaner if the 20 have several challenges. 
source share