4

I have a format :xml Grape::API and for a delete request I want to return an empty response.

Everything I try to enter though, true, false, nil, it tries to convert to xml. How would I go about doing this?

Thanks

Tallboy
  • 12,847
  • 13
  • 82
  • 173

3 Answers3

7

Use:

delete do
  # your code...
  body false
end
sidney
  • 1,241
  • 15
  • 32
1

Usually, you don't. Since blank body is not a valid xml. But if you insist:

module NullXml
  def self.to_xml
    ""
  end
end

# grape endpoint
delete "/something" do
  # do the deletion
  NullXml
end
Aaron Qian
  • 4,477
  • 2
  • 24
  • 27
  • What is the proper response that it should return? I'm using DataMapper which overrides the `to_xml` method in weird ways. I want to make sure I'm returning the proper response if no records are found. – Tallboy Aug 28 '13 at 17:40
  • You should return a status 200 with a valid xml. The xml content can be OK or something like that. – Aaron Qian Nov 05 '13 at 04:31
0

For me this did the trick

    rack_response('', 404)