retrofit api get request not firing the calback methods

130
May 16, 2021, at 6:20 PM

I'm encountering a problem with retrofit : Im trying to make a get request to this API: https://test.spaceflightnewsapi.net/api/v2/articles

But somehow the callbacks methods from the retrofit are not called. I get this in the logcat/ the only thing related to the retrofit (okkhttp):

 I/okhttp.OkHttpClient: --> GET https://test.spaceflightnewsapi.net/api/v2/articles
 I/okhttp.OkHttpClient: --> END GET

here is my api interface:

public interface SpaceNewsApi {
    String BASE_URL = "https://test.spaceflightnewsapi.net/api/v2/";
    @GET("articles")
    Call<List<SpaceNews>> getSpaceNewsArticles();
}

here is the retrofit client (note that i will be using two apis with the retrofit this is why i'm using two methods to build it), also i've added a loginginterceptor, I've change the Level to different types but only the things from above are the messages i get each time in the logs related to retrofit

public class RetrofitClients {
    private static RetrofitClients instance = null;
    private SpaceNewsApi mySpaceNewsApi = null;
    private LaunchLibraryApi myLaunchLibraryApi = null;
    public static synchronized RetrofitClients getInstance() {
        if (instance == null) {
            instance = new RetrofitClients();
        }
        return instance;
    }
    public SpaceNewsApi getMySpaceNewsApi() {
        if(mySpaceNewsApi == null) {
            Retrofit retrofit = new Retrofit.Builder().baseUrl(SpaceNewsApi.BASE_URL)
                    .client(getHttpClient())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            mySpaceNewsApi = retrofit.create(SpaceNewsApi.class);
        }
        return mySpaceNewsApi;
    }
    public  LaunchLibraryApi getMyLaunchLibraryApi(){
        if(myLaunchLibraryApi == null) {
            Retrofit retrofit = new Retrofit.Builder().baseUrl(LaunchLibraryApi.BASE_URL)
                    .client(getHttpClient())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            myLaunchLibraryApi = retrofit.create(LaunchLibraryApi.class);
        }
        return myLaunchLibraryApi;
    }
    public static OkHttpClient getHttpClient() {
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
        //TODO : remove logging interceptors as it is to be used for development purpose
        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(300, TimeUnit.SECONDS)
                .readTimeout(300, TimeUnit.SECONDS)
                .addInterceptor(logging)
                .build();
        return client;
    }
} 

I'm calling all of these in my main activity onCreate method like this:

 //testing Api Call
        Call<List<SpaceNews>> call = RetrofitClients.getInstance().getMySpaceNewsApi().getSpaceNewsArticles();
        call.enqueue(new Callback<List<SpaceNews>>() {
            @Override
            public void onResponse(Call<List<SpaceNews>> call, Response<List<SpaceNews>> response) {
                Log.d("gotApiData","got it");
            }
            @Override
            public void onFailure(Call<List<SpaceNews>> call, Throwable t) {
                Log.d("gotError","not got it");
                t.printStackTrace();
            }
        });

How can I get this working, I would appreciate any advice!

Rent Charter Buses Company
READ ALSO
How to assign URL query parameter before the last parameter in JavaScript

How to assign URL query parameter before the last parameter in JavaScript

I'm trying to build an API Proxy in NodeJS it makes a request to an external 3rd party APIThe API endpoint needs a parameter named "pages=(int)" appended to each request

130
Same fragment creating on sliding in ViewPager2

Same fragment creating on sliding in ViewPager2

I have 2 fragments that I want to show in my viewpager2 but only one shows in the view pager in both the tabs even though I am passing two fragments in my adapter although titles that I set are visible correctly

133
When to use text/plain instead of text/html?

When to use text/plain instead of text/html?

When is it recommended to use text/plain content type over text/html

45
Getting wrong timezone/date from PHP

Getting wrong timezone/date from PHP

When I echo the date_default_timezone_get(); & phpinfo(); I get Europe/Berlin when I should be getting America/New_York

106