Domanda

While I don't think it is very restful to have to include a payload in a DELETE request. I ran into an instance where I am testing a service that requires a payload for DELETE. Might there be a way using Ruby's Rest Client to accomplish this? Unfortunately, I am having a hard time with this one.

@json_request = '{"user_id": 5, "meta_data": "foo"}'
resource = RestClient::Resource.new "http://www.foo.com/some/process"
@response_update = resource.delete(@json_request, :content_type => :json, :accept => :json)

Output: ArgumentError: wrong number of arguments (2 for 0..1)

È stato utile?

Soluzione 2

Currently it's not possible with that gem. You can see a PL addressing that. Maybe you could fork it and pull those changes to your own fork of the rest-client gem.

The pull request https://github.com/rest-client/rest-client/pull/98

Altri suggerimenti

Try this

RestClient::Request.execute(:method => 'delete', :url => "http://www.foo.com", :payload => json_data)

As a very modern update, from the ReadMe

    RestClient::Request.execute(method: :delete, url: 'http://example.com/resource',
                                payload: 'foo', headers: {myheader: 'bar'})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top