How to execute a DELETE query without a return or callback type? [Retrofit]

I need to execute a DELETE query using Retrofit. So, my piece of interface code looks like this:

@DELETE("/api/item/{id}") void deleteItem(@Path("id") int itemId); 

But I get the error:

java.lang.IllegalArgumentException: ApiItem.deleteItem: there must be either a return type or a callback as the last argument.

However, according to the rules of the API Rest, I should not receive a response to a DELETE request. How to specify it in the interface?

Thanks.

+8
java android rest retrofit
source share
2 answers

You must add Callback as the last argument to the request method if you want to use the void method. You can use Callback<Response> .

You should change this:

 @DELETE("/api/item/{id}") void deleteItem(@Path("id") int itemId); 

to:

 @DELETE("/api/item/{id}") void deleteItem(@Path("id") int itemId, Callback<Response> callback); 

Or you can return only Response

 @DELETE("/api/item/{id}") Response deleteItem(@Path("id") int itemId); 
+21
source share

In Retrofit 2.0, you can use the call interface to result in your request, as shown below.

 @DELETE("/api/item/{id}") Call<Response> deleteItem(@Path("id") int itemId); ... Call<Response> call = YourServiceInstance.deleteItem(10); call.enqueue(new Callback<Response>() { ... }); 
+4
source share

All Articles