Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
flask-router
Advanced tools
Flask-inspired routing system for node and connect. Nice if you just need a routing system without depending on connect, or need routing middleware without all features provided by express.
Routing system for node.js/connect based on Flask(http://flask.pocoo.org/).
var connect = require('connect')
, app = connect()
, router = require('flask-router')();
app.use(router.route);
router.get('/users/<str(max=5,min=2):id>', function (req, res) {
console.log(req.params.id);
res.end();
});
router.post('/users/<str(len=7):id>', function (req, res) {
console.log(req.params.id);
res.end();
});
router.put('/customers/<id>', function (req, res) {
console.log(req.params.id);
res.end();
});
Can assign multiple handler functions to the same rule:
router.get('/pattern/that/uses/many/handlers'
, function(req, res, next) {
res.write('part1');
return next();
}, function(req, res, next) {
res.write('part2');
return next();
});
router.get('/pattern/that/uses/many/handlers', function(req, res) {
res.write('part3');
return res.end();
});
// All three handlers will be executed when the url match, so the final
// response will be 'part1part2part3'
Custom parameter parsers can be registered(these are known as 'converters' in Flask/Werkzeug):
router.registerParser('options', function(str) {
var rv = {};
, options = str.split('/')
, i, len, kv, key, value;
for (i = 0, len = options.length; i < len; i++) {
option = options[i];
kv = option.split('=');
key = kv[0], value = kv[1];
rv[key] = value;
}
return rv;
});
router.get('/queryable/<options:query>', function(req, res) {
console.log(JSON.stringify(req.params.query));
res.end();
});
// If '/queryable/gt=5/lt=10/limit=20' was requested,
// the output would be {"limit":"20","gt":"5","lt":"10"}
See tests for more examples.
FAQs
Flask-inspired routing system for node and connect. Nice if you just need a routing system without depending on connect, or need routing middleware without all features provided by express.
The npm package flask-router receives a total of 1 weekly downloads. As such, flask-router popularity was classified as not popular.
We found that flask-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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.