Skip to content

Commit

Permalink
Use 200 as default status for deletes that reply with content
Browse files Browse the repository at this point in the history
  • Loading branch information
jthornec committed Jan 4, 2017
1 parent da20e28 commit 81cf0fb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### Fixes

* [#1548](https://github.com/ruby-grape/grape/pull/1548): Avoid failing even if given path does not match with prefix - [@thomas-peyric](https://github.com/thomas-peyric), [@namusyaka](https://github.com/namusyaka).
* [#1550](https://github.com/ruby-grape/grape/pull/1550): Use 200 as default status for deletes that reply with content - [@jthornec](https://github.com/jthornec).
* Your contribution here.

### 0.19.0 (12/18/2016)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ cookies.delete :status_count, path: '/'

## HTTP Status Code

By default Grape returns a 201 for `POST`-Requests, 204 for `DELETE`-Requests and 200 status code for all other Requests.
By default Grape returns a 201 for `POST`-Requests, 204 for `DELETE`-Requests that don't return any content, and 200 status code for all other Requests.
You can use `status` to query and set the actual HTTP Status Code

```ruby
Expand Down
6 changes: 5 additions & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def status(status = nil)
when Grape::Http::Headers::POST
201
when Grape::Http::Headers::DELETE
204
if @body.present?
200
else
204
end
else
200
end
Expand Down
7 changes: 7 additions & 0 deletions spec/grape/dsl/inside_route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def initialize
expect(subject.status).to eq 204
end

it 'defaults to 200 on DELETE with a body present' do
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE'))
subject.body 'content here'
expect(subject).to receive(:request).and_return(request)
expect(subject.status).to eq 200
end

it 'returns status set' do
subject.status 501
expect(subject.status).to eq 501
Expand Down

0 comments on commit 81cf0fb

Please sign in to comment.