Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return an empty response with grape?

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

like image 706
Tallboy Avatar asked Oct 26 '25 14:10

Tallboy


2 Answers

Use:

delete do
  # your code...
  body false
end
like image 73
Sidney Avatar answered Oct 29 '25 04:10

Sidney


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
like image 22
Aaron Qian Avatar answered Oct 29 '25 06:10

Aaron Qian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!