Created
April 7, 2011 13:13
-
-
Save pofallon/907762 to your computer and use it in GitHub Desktop.
Three req.param() uses and how they interact with app.param()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = module.exports = express.createServer(); | |
app.configure(function(){ | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
}); | |
app.param(':id', function(req, res, next, val) { | |
console.log("Inside app.param with val = " + val); | |
next(); | |
}); | |
// Test 1: param in URL -- *does* call app.param() function | |
// curl http://localhost:3000/test/foo1 | |
app.get('/test/:id', function(req, res){ | |
res.send(); | |
}); | |
// Test 2: query parameter -- does not call app.param() | |
// curl http://localhost:3000/test?id=foo2 | |
app.get('/test', function(req, res){ | |
res.send(); | |
}); | |
// Test 3: form element -- does not call app.param() | |
// curl -d id=foo3 http://localhost:3000/test | |
app.post('/test', function(req, res){ | |
res.send(); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment