How to pass a search parameter in the retrofit with Kotlin?

Asked

Viewed 228 times

-1

I am trying to use the Retrofit library to make HTTP requests for the API: API Star War, with the Kotlin language, however I don’t know how to correctly pass a search parameter to an API function.

Interface code:

 @GET("people/?search=")
    fun getPersonagem(nome: String):Call<PersonagemList>

I’ve tried that way too:

@GET("people/?search={nome}")
    fun getPersonagem(@Path ("nome") nome: String):Call<PersonagemList>

2 answers

0

Good afternoon, blza!? In retrofit version 2 the data encoded by form is sent when @FormUrlEncoded. Each key value pair is annotated with @Fiel of the name and the object providing the value. Make in the following pattern:

@FormUrlEncoded
@POST("Tokencelular")
Call<TokenModel> gravaToken(@Field("tokenDevice") String tokenDevice); //e assim por diante

The GET methods do not require @FormUrlEncoded.

To learn more, visit the documentation: https://square.github.io/retrofit/ and go to topic FORM ENCODED AND MULTIPART

Hugs!

0

Result was thus:

@GET("people/")
fun getPersonagem(@Query("search") name:String):Call Personagemlist

Browser other questions tagged

You are not signed in. Login or sign up in order to post.