Search code examples
androidkotlininterfaceretrofit

Android: How to have data passed to an interface, maybe used as a parameter


I want to use movieId in the @GET() but the thing is I want to use a different variable each time.

I have this interface file, and I am calling it in MainActivity for retrofit. I have tried to () after the interface's name, to pass the data as a parameter, but it doesn't work. What should I do?

interface MovieRecommendationsApiInterface {
    @GET("xxxxxxx")
    fun getRecommendationsList(): Call<MovieResponse>
}

Solution

  • If you want to pass movie id. You can modify your method this way.

    @GET("movies/{id}")
    fun getRecommendationsList(@Path("id") id: Int?): Call<MovieResponse>