Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
express-resource-router
Advanced tools
Simple and semantic restful resource routing for Express
npm install --save express-resource-router
The API is simple - when you require the module, you will be returned the express.Router()
function with eight
new methods appended:
resource
- allows for autoloading of the resource being describedindex
- sets up a '/' get routenew
- sets up a '/new' get routecreate
- sets up a '/' post routeshow
- sets up a '/:id' get routeedit
- sets up a '/:id/edit' get routeupdate
- sets up a '/:id' put routedestroy
- sets up a '/:id' delete route// lets assume this is routes/posts.js
var router = require('express-resource-router');
router.resource(function(id, setResource) {
// the third argument is optional - it sets req.post
// in this case, but req.resource is the default
setResource(null, Post.find(id), 'post');
});
router.index(function(req, res) {
res.render('posts/index', { posts: Post.all() });
});
router.new(function(req, res) {
res.render('posts/new', { post: new Post() });
});
router.create(function(req, res) {
var post = Post.create(/* post params */);
res.redirect(linkTo(post));
});
router.show(function(req, res) {
// without the third parameter above in router.resource(...),
// we would use req.resource
res.render('posts/show', { post: req.post });
});
router.edit(function(req, res) {
res.render('posts/edit', { post: req.post });
});
router.update(function(req, res) {
req.post.update(/* post params */);
res.redirect('back');
});
router.destroy(function(req, res) {
req.post.delete();
res.redirect('/posts');
});
module.exports = router;
Then in your application file...
var app = require('express')();
app.use('/posts', require('./routes/posts'));
And you're good to go.
Right now, I need to write tests for this. If you want to, have at it. Fork and PR, baby.
FAQs
Simple and semantic restful resource routing for Express
We found that express-resource-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.