On Android, I initially implemented a Retrofit interface like this:
@DELETE(USER_API_BASE_URL + "/{id}")
public void deleteUser(@Path("id") String id, Callback<User> callback);
The server returns 204 NO CONTENT upon a successful deletion. This was causing the callback to trigger failure, with retrofit.RetrofitError: End of input at character 0 of
, as it was expecting a User
object back with the response.
I then rewrote it like this, using Void
instead of User
:
@DELETE(USER_API_BASE_URL + "/{id}")
public void deleteUser(@Path("id") String id, Callback<Void> callback); <-- VOID
But I am getting the same error from the callback. What is the proper way to fix this? Thank you.
Retrofit 2.x
no longer has a ResponseCallback
as mentioned in the other answer. You want to use a Response<Void>
type.
The RxJava declaration:
@PUT Observable<Response<Void>> foo();
The standard declaration:
@PUT Call<Response<Void>> bar();
The solution was pointed out by Jake Wharton in the comments. Use ResponseCallback.
EDIT: this response is no longer valid for Retrofit < 2.
This is the kotlin way for the implementation to deal with HTTP 204 and no content.
@DELETE(USER_API_BASE_URL + "/{id}")
suspend fun deleteuser(@HeaderMap headers: Map<String, String>,
@Path("id") id: String)
: Response<Void>
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