85

I have the following code :

    @GET("api.php?company_name={name}")
    Call<Model> getRoms_center(@Query("name") String name);

According to the official docs, I must use @Query, and i'm using it, but i'm getting the following error :

java.lang.IllegalArgumentException: URL query string "company_name={name}" must not have replace block. For dynamic query parameters use @Query.
Jaeger
  • 1,646
  • 8
  • 27
  • 59

4 Answers4

166

You should do it like that instead:

@GET("api.php")
Call<Model> getRoms_center(@Query("company_name") String name);
Gaëtan
  • 11,912
  • 7
  • 35
  • 45
38

Example URL is: http://service.com/movies/list?movie_lang=hindi

for that URL you can use this:

@GET("http://service.com/movies/list")
Single<JsonElement> getMovieList(@Query("movie_lang") String userLanguage);
javadroid
  • 1,421
  • 2
  • 19
  • 43
Narendra
  • 1,010
  • 1
  • 12
  • 11
2

Example Url: https://api.pray.zone/v2/times/today.jsonlatitude=31.3952348&longitude=&elevation=2000&timeformat=1

to pass in retrofit for that URL you can use this:

@GET("today.json")
Call<SalahMainResponse> getSalahTiming(
    @Query("latitude") double latitude,
    @Query("longitude") double longitude,
    @Query("elevation") int elevation,
    @Query("timeformat") int timeformat
);
Rahul
  • 579
  • 1
  • 8
  • 18
0

In Kotlin You should do it like that instead:

Example URL: https://codeforces.com/api/user.info?handles=maity_amit_2003

to pass Retrofit in Kotlin:

interface CodeForcesAPIService {
   @GET("api/user.info?")
   fun getApiResponse(@Query("handles") uid:String): Call<CodeForcesModel>
 }
Amit Maity
  • 15
  • 4