Megi Fernanda
Megi Fernanda

Reputation: 273

How to Make Retrofit Method Get Without Parameter?

i want Get Data with retrofit and i have problem, i will expain with code

ApiService.class :
public interface ApiService {

@GET
Call<ResponseBody> artikel();
}

and my procces class

Call<ResponseBody> get_artikel;
    Retrofit retrofit;
    retrofit = new Retrofit.Builder()
            .baseUrl(Status.HOST_ARTICLE + "content/" + list.get(conversationQueue).conversationId + "/")
            .addConverterFactory(GsonConverterFactory.create())
            .client(httpClient)
            .build();


    ApiService apiService = retrofit.create(ApiService.class);
    get_artikel = apiService.artikel();

if like that, i got error

Missing either @GET URL or @Url parameter.

i know in ApiService i must make Parameter "/content/" in Get, but i need make it in proccess class like this

baseUrl(Status.HOST_ARTICLE + "content/" + list.get(conversationQueue).conversationId + "/")

what the best solution for this?

thanks

Upvotes: 1

Views: 5003

Answers (1)

EpicPandaForce
EpicPandaForce

Reputation: 81569

  retrofit = new Retrofit.Builder()
        .baseUrl(Status.HOST_ARTICLE + "/" )
        .addConverterFactory(GsonConverterFactory.create())
        .client(httpClient)
        .build();

And

public interface ApiService {

     @GET("content/{conversationId}" ) 
     Call<ResponseBody> artikel(@Path("conversationId") String conversationId);
}

Then

apiService.artikel(list.get(conversationQueue).conversationId) ;

Upvotes: 6

Related Questions