Connect - Parameter router
Connect middleware to route connections by query and body parameters.
Installation
$ npm install connect-parameter-router
Basic example
Example below routes all GET / requests with the parameter foo and value bar (/?foo=bar)
connect(
require('connect-parameter-router')(function(app) {
app.get({path : "/", args : {foo : "bar"}}, function(req, res, next) {
res.end("/?foo=bar");
});
});
).listen(3000);
Using multiple parameters
Routes can also be defined with multiple parameters
In the example below the route would match every GET / request with parameter foo with value bar and parameter bar with value foo
connect(
require('connect-parameter-router')(function(app) {
app.get({path:"/", args : {foo : "bar", bar : "foo"}}, function(req, res, next) {
res.end("foo=bar and bar=foo");
});
});
).listen(3000);
Using different request methods
Routes can be defined for get, post, put, delete, connect, options, trace, copy, lock, mkcol, move, propfind, proppatch, unlock, report, mkactivity, checkout and merge request methods.
connect(
require('connect-parameter-router')(function(app) {
app.get({path : "/", args : {foo : "bar"}}, function(req, res, next) {
res.end("GET request received with parameter foo=bar");
});
app.post({path : "/", args : {foo : "bar"}}, function(req, res, next) {
res.end("POST request received with parameter foo=bar");
});
});
).listen(3000);
Licence
Largely based on the original Connect - router by Sencha Inc. and TJ Holowaychuk
(The MIT License)
Copyright(c) 2010 Sencha Inc. (Connect - router)
Copyright(c) 2011 TJ Holowaychuk (Connect - router)
Copyright(c) 2011 Applifier Ltd. (Connect - parameter router)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.