godfat / rest-core

Various rest-builder middleware for building REST clients.
Apache License 2.0
57 stars 13 forks source link

A payload within a DELETE request is ignored resulting "Invalid request data" from web services. #25

Closed AshwiniDoddamaniFluke closed 7 years ago

AshwiniDoddamaniFluke commented 7 years ago

I am trying to send a DELETE request with a REQUEST_PAYLOAD that carries list of ids in JSON format which gets ignored from the web services. The same request used to work with a very old version of rest-core '2.1.2' Currently i am using 'rest-core', '4.0.1' with ruby 2.3.3 on rails 5.0.0 in which it fails. Could this be an issue with httpclient?

godfat commented 7 years ago

I remembered that I once touched this, because I realized that DELETE shouldn't have any payload according to the specification.

However if that works, and people need it, I don't mind to support it. Could you please see if this patch would work for you?

diff --git a/lib/rest-builder/middleware.rb b/lib/rest-builder/middleware.rb
index 230da59..aa16fed 100644
--- a/lib/rest-builder/middleware.rb
+++ b/lib/rest-builder/middleware.rb
@@ -1,7 +1,7 @@

 module RestBuilder
   module Middleware
-    METHODS_WITH_PAYLOAD = [:post, :put, :patch]
+    METHODS_WITH_PAYLOAD = [:post, :put, :patch, :delete]

     def self.included mod
       mod.send(:attr_reader, :app)

Note that this is now implemented in https://github.com/godfat/rest-builder so you'll need to apply the patch there. Let me know if you don't know how to patch it.

AshwiniDoddamaniFluke commented 7 years ago

Yes. I was able to patch that in rest-builder & DELETE is working perfectly with the change. It is needed for us to perform batch deletions where we wish to send bulk Ids in the REQUEST_PAYLOAD.

AshwiniDoddamaniFluke commented 7 years ago

Thank you very much for the release. You are simply amazing!

godfat commented 7 years ago

Oh, I was just about to say that I released rest-builder 0.9.2 :)

Thank you for confirming and using rest-core.