question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Delete Method with Retrofit 2.0

See original GitHub issue

Accoring to @JakeWharton it is possible to overwrite Rest Methods. I need a customized method (DELETE with Body) as it isn´t allowed by retrofit even if it´s allowed by rfc spec. But this does not work anyore since the Annotation @RestMethod was removed since retrofit 2.0 So how can I send now a HTTP-DELETE with Body?

see alsow: https://github.com/square/retrofit/issues/426 and https://github.com/square/okhttp/issues/605

If I use default mechnism of retrofit 2.0 i get a stacktrace

@DELETE("/myurl")
    Call<String> deactivateUserPermanently(
            @Header("Authorization") String systemAuthLine,
            @Body MyBodyRequest myBodyRequest
    );
java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.
    for method MyProxy.deactivateUserPermanently
    at retrofit.Utils.methodError(Utils.java:177)
    at retrofit.Utils.methodError(Utils.java:167)
    at retrofit.RequestFactoryParser.parseParameters(RequestFactoryParser.java:359)
    at retrofit.RequestFactoryParser.parse(RequestFactoryParser.java:60)
    at retrofit.MethodHandler.create(MethodHandler.java:30)
    at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151)
    at retrofit.Retrofit$1.invoke(Retrofit.java:132)
    at com.sun.proxy.$Proxy7.deactivateUserPermanently(Unknown Source)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

52reactions
nindzyagocommented, Mar 20, 2016

Actually, the correct syntax is: @HTTP(method = “DELETE”, path = “/foo”, hasBody = true)

10reactions
chinmaygitcommented, Feb 29, 2016

@Zhuinden This is correct one. interface Example { @HTTP(method = “DELETE”, path = “/foo, hasBody = true”) Call method(); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retrofit 2.0 how to delete? - java - Stack Overflow
Do it this way as you noted last: Call<ResponseBody> deleteBook(@Path("id") int bookId);. Make sure you make the call off the UI-thread via ...
Read more >
Retrofit 2 — How to Delete Objects on the Server - Future Studio
Summary. In this tutorial you've learned how to delete objects on the server. Deleting objects is quite easy with the DELETE HTTP method....
Read more >
Remove Resource in server: Android Retrofit in Kotlin #5.4
... 60 days FREE: https://pluralsight.pxf.io/c/1291657/424552/7490 Retrofit Android using Kotlin. Learn to perform HTTP DELETE request a...
Read more >
HTTP (Retrofit 2.7.1 API)
Use a custom HTTP verb for a request. interface Service { @HTTP(method = "CUSTOM", path = "custom/endpoint/") Call<ResponseBody> customEndpoint(); }
Read more >
Retrofit Android Example Tutorial - DigitalOcean
The getClient() method in the above code will be called every time while setting up a Retrofit interface. Retrofit provides with a list...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found