22nd
Net::HTTP missing delete — a reprieve
Earlier today I wrote
I just got really screwed over by Net::HTTP
The docs talk about a nice delete method for sending HTTP DELETE requests, however it turns out that it does not exist
>> Net::HTTP.methods.include?("delete") => falseI am somewhat annoyed, especially given we asked a third-party to respond to DELETE requests, and now have to figure out a way to send them! Bad ruby! Bad Net HTTP!
Turns out it was mostly my mistake (isn’t it always), but i blame rdoc for being somewhat less than clear!
Delete is not a class method (though given that Get is, i think Delete should be too), so the correct way to use it is
uri = URI.parse("http://server.example.com:8080/path/to/resource?var=value")
request = Net::HTTP.new(uri.host, uri.port)
response = request.delete(uri.request_uri)
Make sure you only give the uri.host to Net::HTTP.new and not uri.to_s otherwise you get annoying errors; and that you use uri.request_uri not request.path when creating the path for the delete method, as the path does not include any query params