我创建了如下所示的API:
interface listProd {
@GET("v1/{type}")
fun getProduct(
@Path("type") type: String): Observable<Response>
}
现在我需要添加一个参数以使其如下所示:
interface listProd {
@GET("v1/{type}?preview=true")
fun getProduct(
@Path("type") type: String): Observable<Response>
}
但是我不想一直都有它。目的是要了解如何在布尔条件下添加?preview=true
,我不想有多个接口,但是想添加或不添加一个聪明的方法。
条件可以是getProduct
中的布尔传递,这会触发是否附加?preview=true
任何想法 谢谢
答案 0 :(得分:0)
您应该能够为此使用可选的查询参数:
@GET("v1/{type}")
fun getProduct(
@Path("type") type: String,
@Query("preview") preview: Boolean?
): Observable<Response>
需要注意的是,传入true
或false
将包含该参数,而null
则将其完全省略。