Remove req.param()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent a7d15f3 · Browse files · 3 files·+1 added−96 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+1 added−96 removed
- tests:+0 added−61 removed
- other:+1 added−35 removed
Provenance
- Commit
21d52da- Tree
0c5824b- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
a7d15f3
3 files changed+1 added−96 removed
modified:lib/request.js-35 removed
12 unmodified lines13 * @private14 */15 16 var accepts = require('accepts');17-var deprecate = require('depd')('express');17 var isIP = require('net').isIP;18 var typeis = require('type-is');19 var http = require('http');20 var fresh = require('fresh');188 unmodified lines209 return queryparse(querystring);210 });211 212 /**214- * Return the value of param `name` when present or `defaultValue`.215- *216- * - Checks route placeholders, ex: _/user/:id_217- * - Checks body params, ex: id=12, {"id":12}218- * - Checks query string params, ex: ?id=12219- *220- * To utilize request bodies, `req.body`221- * should be an object. This can be done by using222- * the `bodyParser()` middleware.223- *224- * @param {String} name225- * @param {Mixed} [defaultValue]226- * @return {String}227- * @public228- */229-230-req.param = function param(name, defaultValue) {231- var params = this.params || {};232- var body = this.body || {};233- var query = this.query || {};234-235- var args = arguments.length === 1236- ? 'name'237- : 'name, default';238- deprecate('req.param(' + args + '): Use req.params, req.body, or req.query instead');239-240- if (null != params[name] && params.hasOwnProperty(name)) return params[name];241- if (null != body[name]) return body[name];242- if (null != query[name]) return query[name];243-244- return defaultValue;245-};246-247-/**213 * Check if the incoming request contains the "Content-Type"214 * header field, and it contains the give mime `type`.215 *216 * Examples:263 unmodified linesdeleted:test/req.param.js-61 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
var express = require('../') , request = require('supertest') , bodyParser = require('body-parser')
describe('req', function(){ describe('.param(name, default)', function(){ it('should use the default value unless defined', function(done){ var app = express();
app.use(function(req, res){ res.end(req.param('name', 'tj')); });
request(app) .get('/') .expect('tj', done); }) })
describe('.param(name)', function(){ it('should check req.query', function(done){ var app = express();
app.use(function(req, res){ res.end(req.param('name')); });
request(app) .get('/?name=tj') .expect('tj', done); })
it('should check req.body', function(done){ var app = express();
app.use(bodyParser.json());
app.use(function(req, res){ res.end(req.param('name')); });
request(app) .post('/') .send({ name: 'tj' }) .expect('tj', done); })
it('should check req.params', function(done){ var app = express();
app.get('/user/:name', function(req, res){ res.end(req.param('filter') + req.param('name')); });
request(app) .get('/user/tj') .expect('undefinedtj', done); }) })})modified:History.md+1 added
3 unmodified lines4 This incorporates all changes after 4.10.1 up to 4.13.1.5 6 * remove:7 - `app.param(fn)`8+ - `req.param()` -- use `req.params`, `req.body`, or `req.query` instead9 * change:10 - The leading `:` character in `name` for `app.param(name, fn)` is no longer removed11 12 5.0.0-alpha.1 / 2014-11-063012 unmodified lines