GET api with Retrofit

亡梦爱人 提交于 2019-12-11 03:38:30

问题


I have a web service link which I want to hit with different customerId in the form of

 http://apidev.myserver.com.au:8980/TestService/rest/TestService/jobs/bycustid/customerId

how do I append the value of customerId?

this is my base URL :

 http://apidev.myserver.com.au:8980/TestService/rest/TestService/

this is what my interface for calls look like :

interface CustomerJobs {
    @GET("jobs/bycustid/11726")
    Call<CustomerJobsPojo> getCustomerJobs();
}

回答1:


As the doc says :

interface CustomerJobs {

    @GET("jobs/bycustid/{id}")
    Call<CustomerJobsPojo> getCustomerJobs(@Path("id") int id);

}



回答2:


Try @Path annotation

interface CustomerJobs {
    @GET("jobs/bycustid/{id}")
    Call<CustomerJobsPojo> getCustomerJobs(@Path("id") String id);
}



回答3:


You can embed like

@GET("jobs/bycustid/{custId}")
     Call<CustomerJobsPojo> groupList(@Path("custId") int custId);



回答4:


Yes you can use dynamic urls

interface CustomerJobs {

    @GET("jobs/bycustid/{customerid}")
    Call<CustomerJobsPojo> getCustomerJobs(@Path("id") int customerid);

}

Refer this



来源:https://stackoverflow.com/questions/42689463/get-api-with-retrofit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!