Skip to content

Commit 553331a

Browse files
committed
Use 200 as default status for deletes that reply with content
1 parent da20e28 commit 553331a

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#### Fixes
1010

1111
* [#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).
12+
* [#1550](https://github.com/ruby-grape/grape/pull/1550): Use 200 as default status for deletes that reply with content - [@jthornec](http://github.com/jthornec).
1213
* Your contribution here.
1314

1415
### 0.19.0 (12/18/2016)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ cookies.delete :status_count, path: '/'
17641764

17651765
## HTTP Status Code
17661766

1767-
By default Grape returns a 201 for `POST`-Requests, 204 for `DELETE`-Requests and 200 status code for all other Requests.
1767+
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.
17681768
You can use `status` to query and set the actual HTTP Status Code
17691769

17701770
```ruby

lib/grape/dsl/inside_route.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ def status(status = nil)
130130
when Grape::Http::Headers::POST
131131
201
132132
when Grape::Http::Headers::DELETE
133-
204
133+
if @body.present?
134+
200
135+
else
136+
204
137+
end
134138
else
135139
200
136140
end

spec/grape/dsl/inside_route_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ def initialize
111111
expect(subject.status).to eq 204
112112
end
113113

114+
it 'defaults to 200 on DELETE with a body present' do
115+
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE'))
116+
subject.body 'content here'
117+
expect(subject).to receive(:request).and_return(request)
118+
expect(subject.status).to eq 200
119+
end
120+
114121
it 'returns status set' do
115122
subject.status 501
116123
expect(subject.status).to eq 501

0 commit comments

Comments
 (0)