0

I am trying to use retrofit2 to make an api call, here's my code

public class MainActivity extends Activity implements Callback<List<Repo>>{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ApiCLient apiCLient = new ApiCLient(); IApiService apiService = apiCLient.getApiService(); Call<List<Repo>> call = apiService.getRepos(); call.enqueue(this); } @Override public void onResponse(Call<List<Repo>> call, Response<List<Repo>> response) { if (response.isSuccessful()) { List<Repo> repos = response.body(); } else { ResponseBody a = response.errorBody(); Log.d("asd", response.errorBody().toString()); } } @Override public void onFailure(Call<List<Repo>> call, Throwable t) { Log.d("asd", t.getLocalizedMessage()); } } 

I'm not getting any response. Also, debugger is not entering the onResponse or onFailure methods.

ApiClient class

private IApiService mService; static final String BASE_URL = "https://api.github.com"; public ApiCLient(){ Retrofit retrofit = null; try { Gson gson = new GsonBuilder().setLenient().create(); retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); } catch (Exception e){ e.printStackTrace(); } mService = retrofit.create(IApiService.class); } public IApiService getApiService(){ return mService; } 

And finally, IApiService interface

public interface IApiService { @GET("https://api.github.com/repositories?since=364") Call<List<Repo>> getRepos(); } 

1 Answer 1

1

you should use this code :

public interface IApiService { @GET("repositories?since=364") Call<List<Repo>> getRepos(); } 

for your interface . and use

static final String BASE_URL = "https://api.github.com/"; 

for BASE_URL.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.