Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change a url subdirectory to a variable in retrofit?

Any Idea how can I change the id subdirectory to a variable that will takes the value of the function argument?
The id query is incorrect since it’s gonna be after information.

@GET("recipes/id/information")
suspend fun getRecipeInformation(
    @Query("id")
     id: Int,
    @Query("apiKey")
     apiKey: String) : Response<RecipesByIngredientsResponse>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If my understanding is correct, you have to define the id argument as a Path variable, instead of Query:

@GET("recipes/{id}/information")
suspend fun getRecipeInformation(
    @Path("id")
     id: Int,
    @Query("apiKey")
     apiKey: String) : Response<RecipesByIngredientsResponse>

Notice the syntax:

  • the id is in curly braces
  • Path annotation is used instead of Query

Official documentation: Path

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading