I'm with a problem with Retrofit 2. I want to use the Call<Void>
to make a call without handle the response body, but it doesnt work with Kotlin.
What I need to use instead of Void
?
I want to use the Call to make a call without handle the response body, but it doesnt work with Kotlin
That is not true, it does work.
Something different must be wrong with your setup, or your test case is ill defined if you don't get the expected result.
A very simple example:
interface GitHub {
@GET("/users/{username}/repos")
fun getUserRepos(@Path("username") username: String): Call<Void>
}
val github = Retrofit.Builder()
.baseUrl("https://api.github.com/")
.build()
.create(GitHub::class.java)
github.getUserRepos("maciekjanusz")
.enqueue(object : Callback<Void> {
override fun onFailure(call: Call<Void>?, t: Throwable?) {
// failure
}
override fun onResponse(call: Call<Void>?, response: Response<Void>?) {
// success
}
})
I tried the above snippets in an Android example, using Kotlin 1.1.61 and Retrofit 2.3.0 and it works correctly - the call is executed and depending on the network availability and the overall setup, the correct Callback
method is called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With