Retrofit 2 Query, get back response?

Stoffe1985 Source

How could i access with the correct syntax: api/kiosk/search/staff?companyID={companyID}&locationID={locationID}&name={name}

Right now i do this:

Call<Staff[]> staffItems(@Path("companyID") String companyID,@Query("locationId") String locationId, @Query("name") String name, @Header("Authorization")String auth);


answered 5 days ago Santanu Sur #1

You can use dynamic Url with retrofit.. just like the following piece of code..

public Call<ResponseBody> profilePicture(@Url String url);

Your Url goes here... For eg your retro builder looks like this ..

Retrofit retrofit = Retrofit.Builder()  

  UserService service = retrofit.create(UserService.class);  
  // request url results in:

Note - if you pass a completely different Url to the service... okhttp will automatically take the url that you pass , in this case .. .On the other hand if you pass something like this as the url -> service.profilePicture("profile-picture/path"); the full URL will be https://your.api.url/profile-picture/path

So , go ahead and build your dynamic url like this :-

String url = "api/kiosk/search/staff?companyID="+companyID"+"&locationID= "+locationID+"&name="+name"; and then pass the url like ..

and your interface call statement would look like this ...

@GET Call<Staff[]> staffItems(@Url url);


answered 5 days ago ヅ fix #2

Try this

Call<Staff[]> staffItems(@Query("companyID") String companyID,@Query("locationId") String locationId, @Query("name") String 
name, @Header("Authorization")String auth);

comments powered by Disqus