-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change HTTP DELETE status code and body logic, use nil for HTTP 204 #1774
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
Upgrading Grape | ||
=============== | ||
### Upgrading to >= ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a change in API I would make this 1.2, so bump that version part of this PR. The section below becomes "Upgrading to >= 1.2". The explanation can be clearer. Instead of "Currently" say "Since version 1.2 returning ...". There's also confusion here between Match the title to Returning an empty Hash or Array will no longer return 204 from HTTP DELETE. Add a blank line after ;) |
||
#### Changes in HTTP Delete Response Body and HTTP status code | ||
Previously, using `body false` or returning an empty Hash/Array would result in a empty response body and HTTP 204 (No content). | ||
Currently, returning an empty Hash or Array will return the corresponding json/xml string and HTTP 200. Calling `body nil` or setting the response body to `nil` or using `return_no_content` will return an empty response body and HTTP 204. | ||
|
||
### Upgrading to >= 1.1.1 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,10 +178,10 @@ def status(status = nil) | |
when Grape::Http::Headers::POST | ||
201 | ||
when Grape::Http::Headers::DELETE | ||
if @body.present? | ||
200 | ||
else | ||
if @body.nil? | ||
204 | ||
else | ||
200 | ||
end | ||
else | ||
200 | ||
|
@@ -222,12 +222,17 @@ def cookies | |
# end | ||
# | ||
# GET /body # => "Body" | ||
def body(value = nil) | ||
if value | ||
@body = value | ||
elsif value == false | ||
@body = '' | ||
status 204 | ||
def body(*value) | ||
raise ArgumentError 'you can only set a body with one argument' if value.length > 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the text is not required, just What if value is This needs a test. You can also turn this into a separate PR if you want. |
||
|
||
if value.length == 1 | ||
value = value.first | ||
if value.nil? | ||
@body = '' | ||
status 204 | ||
else | ||
@body = value | ||
end | ||
else | ||
@body | ||
end | ||
|
@@ -244,7 +249,7 @@ def body(value = nil) | |
# DELETE /12 # => 204 No Content, "" | ||
def return_no_content | ||
status 204 | ||
body false | ||
body nil | ||
end | ||
|
||
# Allows you to define the response as a file-like object. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets clarify this a little bit. How about this:
Returning an empty Hash or Array will no longer return 204 from HTTP DELETE
What's the story with WEBrick?