I have query like that:
getData(number: String)
@GET("/myapp/{number}/details")
fun getData(
@Path number: String
)
But I would like to create something like:
getData(withAdditionalParam: Boolean, number: String)
@GET("/myapp/{number}/details?sometimesAdditionalParam="number")
fun getData(
@Path number: String,
? what here ?
)
At the moment I have 2 separate GET functions but I belive we can achieve it using 1 get function
CodePudding user response:
Argument can be annotated with @Query
@GET("/myapp/{number}/details")
fun getData(
@Path("number") number: String,
@Query("sometimesAdditionalParam") sometimesAdditionalParam: Boolean? = null
)
Assigning default null value to query parameter does not append query param sometimesAdditionalParam
to request
CodePudding user response:
You can make the additional param nullable so that Retrofit only passes it if it's not null.
@GET("/myapp/{number}/details")
fun getData(
@Path number: String,
@Query("sometimesAdditionalParam") additionalParam : Boolean? = null
)
when you want to pass it
getData(number: String, true)
when you don't
getData(number: String)
CodePudding user response:
Which programming language are you using is JavaScript?
If you give a bit more information I will be able to help. Good luck and let me know