Is there a way to change the default "id" in express-resource from *.<name>
to *.id
?
Example app.js:
...
app.resource('projects', require('./resoureces/project')
...
How it is now :
exports.show = function(req, res){
console.log("got id", req.params.project)
})
What I want:
exports.show = function(req, res){
console.log("got id", req.params.id)
})
I want this is because I don't want the project.js file to have to know about what I wrote in the app.js file to know what the ID is.
And I know this probably will bring problems when i have multiple ids because of nesting, but it would be nice to have at the top level at least. Or a generic way to access multiple ids, for instance id, id2 id3... idX and so on.
After taking a look at the express-resource source I found an option not documented to define your own id per resource. If you take a look at the tests in test/resource.test.js
you'll find a test explaining how this option is used:
var app = express();
app.resource('users', {
id: 'uid',
...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.