Question

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?

Was it helpful?

Solution

Here's one way using HTTParty:

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

OTHER TIPS

it could be used her. This is ORM for api. https://github.com/remiprev/her

Example of usage:

RestResource.destroy_existing(id, body_params)

I also spent some time on this issue and @Casper's answer shed the light.

Seems to me that the key is to pass the body value as JSON string, which is not written in most of the documentations I found.

Here's another example using httpclient

require 'json'
body = { 'items': [{ 'type': 'type1', 'item_id': 'item1' }]}
HTTPClient.new.delete('http://api.com/endpoint_path/rest_resource', body.to_json)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top