I need perform a DELETE request using Retrofit. So, my code snippet of the interface looks like this:
@DELETE(\"/api/item/{id}\")
void deleteItem(@Path(\"id\") i
In Retrofit 2.0, You can use Call interface for the result of your request as below.
@DELETE("/api/item/{id}")
Call<Response> deleteItem(@Path("id") int itemId);
...
Call<Response> call = YourServiceInstance.deleteItem(10);
call.enqueue(new Callback<Response>() {
...
});
@FormUrlEncoded
@HTTP(method = "DELETE", path = "manage-feed", hasBody = true)
Call<ResponseBody> deletePost(@Field("post_id") Integer postId, @Field("share_id") Integer sharedMapId);
You have to add Callback as last argument in request method if you want to have void method. You can useCallback<Response>
.
You have to 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 just Response
@DELETE("/api/item/{id}")
Response deleteItem(@Path("id") int itemId);
@HTTP(method = "DELETE", path = "/api/item/{id}", hasBody = false)
fun deleteItemId(
@Path("id") id: Int
) : Call<YourResponse>
hasBody =
true -> if api has request body
false -> if api has not a request body