grape: Revert #1532 set default 204 for deletes

This MR: https://github.com/ruby-grape/grape/pull/1532 is plain wrong.

204 is only when there is NO CONTENT meaning I explicitly as a developer set body false. I now have to go through all my delete calls and explicitly set status 200, which makes no sense.

For example returning the deleted object is quite common, now we don’t follow the spec because by default (even when there is body!) we return 204.

mind blown

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (16 by maintainers)

Most upvoted comments

This just bit me too. We’re using Grape with grape-roar something like this:

delete do
  model.destroy!
  present model, with: ModelPresenter
end

After updating Grape, our API DELETE endpoints started returning #<Model:0x00000000> instead of the expected { "model": "json" } because the new 204 status code is causing the formatter to be skipped.

This behaviour is a bit surprising, as I didn’t immediately connect the new 204 No Content header to Grape skipping the formatter but still returning content.

@JanStevens if you don’t have time to put a PR together in the next few days, I might be able to do it.

Or at least we should evaluate if a body is returned and then return 200 else 204.

Less magic, more explicitness, happy devs 👍