Skip to content

Commit

Permalink
Remove res.json(status, obj) signature
Browse files Browse the repository at this point in the history
closes #2939
  • Loading branch information
tunniclm authored and dougwilson committed Jan 28, 2017
1 parent a856456 commit 25fdefa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 25 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This incorporates all changes after 4.13.1 up to 4.14.0.

* remove:
- `res.json(status, obj)` signature - use `res.status(status).json(obj)`
- `res.vary()` (no arguments) -- provide a field name as an argument

5.0.0-alpha.2 / 2015-07-06
Expand Down
11 changes: 1 addition & 10 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,11 @@ res.send = function send(body) {
*/

res.json = function json(obj) {
var val = obj;

// support res.json(status, obj)
if (arguments.length === 2) {
deprecate('res.json(status, obj): Use res.status(status).json(obj) instead');
this.statusCode = arguments[0];
val = arguments[1];
}

// settings
var app = this.app;
var replacer = app.get('json replacer');
var spaces = app.get('json spaces');
var body = stringify(val, replacer, spaces);
var body = stringify(obj, replacer, spaces);

// content-type
if (!this.get('Content-Type')) {
Expand Down
15 changes: 0 additions & 15 deletions test/res.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,4 @@ describe('res', function(){
})
})
})

describe('.json(status, object)', function(){
it('should respond with json and set the .statusCode', function(done){
var app = express();

app.use(function(req, res){
res.json(201, { id: 1 });
});

request(app)
.get('/')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(201, '{"id":1}', done)
})
})
})

0 comments on commit 25fdefa

Please sign in to comment.