Home > Software design >  How do i use a parameter with a api call using retrofit
How do i use a parameter with a api call using retrofit

Time:11-01

I need to use a parameter to access a different api query depending on what the user choses.

I am trying to get to http://hp-api.herokuapp.com/api/characters/house/Slytherin

    @GET("api/characters/house")
suspend fun getAllHouse(@Query("/") search: String ): House

CodePudding user response:

You want add variable inside your path like this

@GET("api/characters/house/{city}")

and you will pass it on parameter function like this

suspend fun getAllHouse(@Path("city") city: String ): House

CodePudding user response:

Just use this code and concatenate response url string parameters will get this data

      @GET
      suspend fun getAllHouse(@Url String url): Call<List<House>>
  • Related