Doubt creating the interface to consume apis with Retrofit when it does not have the @PATH [duplicated]

0

As the title of the question correctly says, I am trying to show a list of countries with the following URL given by the teacher link , for this I created an interface in the following way:

public interface ICountryService {

    String ENDPOINT = "https://restcountries.eu";


    @GET("/rest/v1/all")
    Call<List<Country>> getCountry(@Path("country") String country);


}

The fact is that he will not let me remove the @PATH because it gives an error but I suspect that he should not take it, because the list of countries is in that URL.

    
asked by Jose 26.11.2016 в 22:07
source

1 answer

2

Ideally you should separate the url into pieces, you can create a new class, something like that (I write the code without editor, head, there may be some failure)

public class Constans{

public static final String URL ="https://restcountries.eu";
public static final String SERVICE_TYPE ="/rest";
public static final String API_VERSION = "/v1";
public static final String BASE_URL = URL+SERVICE_TYPE+API_VERSION;
}

When retrofit instances you can do something like this:

 Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constans.BASE_URL) //todos los demás parametros

and then

@GET("/all")
    Call<List<Country>> getCountry();
    
answered by 27.11.2016 / 20:32
source