title: Is there a way to send JSON with DELETE request with Net::HTTP?
body: <p>I am using Net::HTTP for CRUD request in Sinatra application. For a delete request I need to send JSON along with request:</p>
  
  <pre><code>uri = URI.parse('http://localhost:3000')    
  http = Net::HTTP.new(uri.host, uri.port)
  path = '/resource/resource-id'
  request = Net::HTTP::Delete.new(path)
  request.basic_auth('username', 'password')
  
  response = http.request(request)
  </code></pre>
  
  <p>The above code sends DELETE request just fine, but when I send JSON, </p>
  
  <pre><code>request = Net::HTTP::Delete.new(path, '{"ids": ["abc123"]}')
  request.basic_auth('username', 'password')
  
  response = http.request(request)
  </code></pre>
  
  <p>it throws: </p>
  
  <pre><code>'400 Invalid URI'    
  </code></pre>
  
  <p>I have used HTTParty gem a lot and I know it serves this purpose, but I do not want to include a gem for just one API.</p>
  
  <p>Any help/pointers are greatly appreciated.</p>
  
  <p><strong>Update</strong>
  As @kimball and @Zoker suggested, here is what I did (I am using ruby-2.0.0-p643 MRI):</p>
  
  <pre><code>request = Net::HTTP::Delete.new(path, {'Depth' =&gt; 'Infinity', 
                                         'Content-Type' =&gt;'application/json'})
  request.body = '{"ids":["abc123"]}'
  request.basic_auth('username', 'password')
  
  response = http.request(request)
  </code></pre>
  
  <p>it throws: </p>
  
  <pre><code>'400 Invalid URI'    
  </code></pre>
  
  <p><strong>Update 2</strong>
  Again as suggested in comments: </p>
  
  <pre><code>require 'json'
  request.body = {"ids" =&gt; ["abc123"]}.to_json
  </code></pre>
  
  <p>result is still the same.</p>
  
  <pre><code>response = http.request(request)
  =&gt; #&lt;Net::HTTPBadRequest 400 Invalid URI readbody=true&gt;
  </code></pre>