Remove res.json(status, obj) signature

closes #2939
This commit is contained in:
Mike Tunnicliffe 2016-03-14 11:47:38 +00:00 committed by Douglas Christopher Wilson
parent a856456a95
commit 25fdefac45
3 changed files with 2 additions and 25 deletions

View File

@ -4,6 +4,7 @@
This incorporates all changes after 4.13.1 up to 4.14.0. This incorporates all changes after 4.13.1 up to 4.14.0.
* remove: * remove:
- `res.json(status, obj)` signature - use `res.status(status).json(obj)`
- `res.vary()` (no arguments) -- provide a field name as an argument - `res.vary()` (no arguments) -- provide a field name as an argument
5.0.0-alpha.2 / 2015-07-06 5.0.0-alpha.2 / 2015-07-06

View File

@ -203,20 +203,11 @@ res.send = function send(body) {
*/ */
res.json = function json(obj) { 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 // settings
var app = this.app; var app = this.app;
var replacer = app.get('json replacer'); var replacer = app.get('json replacer');
var spaces = app.get('json spaces'); var spaces = app.get('json spaces');
var body = stringify(val, replacer, spaces); var body = stringify(obj, replacer, spaces);
// content-type // content-type
if (!this.get('Content-Type')) { if (!this.get('Content-Type')) {

View File

@ -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)
})
})
}) })