how to get the value from random number api using retrofit?

57 Views Asked by At

URL : https://www.randomnumberapi.com/api/v1.0/random

using the above api im unable to get the values as String or either int, can someone help me how to get this value inside my code?

here's what i tried

main class code:


Retrofit retrofit = new Retrofit.Builder()
        .addConverterFactory(GsonConverterFactory.create())
        .baseUrl(url)
        .build();
Api api=retrofit.create(Api.class);

Call<String> getNum=api.getValues();
getNum.enqueue(new Callback<String>() {
    @Override
    public void onResponse(Call<String> call, Response<String> response) {
        if(!response.isSuccessful()){
            textView.setText("code : "+response.code());
        }else{
            textView.setText(response.body());
        }
    }

    @Override
    public void onFailure(Call<String> call, Throwable t) {
        textView.setText(t.getMessage());

    }
});

Interface:

import retrofit2.Call;
import retrofit2.http.GET;

import java.util.List;

public interface Api {
    @GET("random")
    Call<String> getValues();

how to get the value from random number api using retrofit and use the values in the project

0

There are 0 best solutions below