rubyhttprequestcurb

How to send DELETE request with body using ruby gem?


I am communicating with API that requires DELETE request with JSON body. This works on console:

curl -XDELETE http://api.com/endpoint_path/rest_resource -d '{"items":[{"type":"type1","item_id":"item1"}]}'

It seems that most gems for making HTTP requests don't support DELETE request with body (I tried RestClient and Curb). Is there a way to do it using some Ruby gem (preferably Curb) or Net::HTTP?


Solution

  • Here's one way using HTTParty:

    HTTParty.delete("http://api.com/endpoint_path/rest_resource", { 
      :body => '{"items":[{"type":"type1","item_id":"item1"}]}'
    })