API Interface
public interface YourUsersApi {
@GET("/name/{name}")
public void getName(@Path("name") String user, Callback<pojo> response);
@GET("/gender/{gender}")
public void getName(@Path("gender") String user, Callback<pojo> response);
}
MainActivity
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://yourserveraddress.com").build();
YourUsersApi yourUsersApi = restAdapter.create(YourUsersApi.class);
If I want to acces "https://yourserveraddress.com/users/matthew", I would add this code into MainActivity
:
git.getPlaces(KEY, new Callback<pojo>() {
@Override
public void success(pojo pojo, Response response) {
Log.d("test1", "success");
}
@Override
public void failure(RetrofitError error) {
Log.d("test1", error.toString());
}
});
Two problems arise though:
How would I do it if I want to acces "https://yourserveraddress.com/users/matthew/gender/male"? do I need to concatenate the
interface methods
together or some sort?Is there a much efficient way to write the
interface methods
? I feel like creating ananonymous class
for each one is inefficient.
There are multiple ways we can use retrofit. If you do not want to use anonymous class so you can also follow below code.
API Interface
For this you can get more idea about it from this link : https://medium.com/@shelajev/how-to-make-http-calls-on-android-with-retrofit-2-cfc4a67c6254#.llvydsa8a