Picker - Server Side Router for Meteor
Picker is an easy to use server side router for Meteor. This router respect others. So, you can use Iron Router and other routers and middlewares along side with this.
Install
meteor add meteorhacks:picker
Getting Started
1 2Picker.route('/post/:_id', function(params, req, res, next) { 3 var post = Posts.findOne(params._id); 4 res.end(post.content); 5}); 6
- You can use Meteor APIs inside this callback (runs inside a Fiber)
- Route definitions are very similar to Iron Router and Express
reqis an instance of NodeJS http.IncomingMessageresis an instance of NodeJS http.ServerResponsenextis optional and call it, if you don't need to handle the current request
Filtering and Sub Routes
This is an unique functionality of this router. See following example:
Let's say we need to handle only POST requests. This is how you can do it with Picker.
1var postRoutes = Picker.filter(function(req, res) { 2 // you can write any logic you want. 3 // but this callback does not run inside a fiber 4 // at the end, you must return either true or false 5 return req.method == "POST"; 6}); 7 8postRoutes.route('/post/:id', function(params, req, res, next) { 9 // ... 10});
You can create any amount of sub routes with this filter API. Same time, you can create nested sub routes as well.
Middlewares
You can use existing connect and express middlewares without any issues.
1var bodyParser = Meteor.npmRequire('body-parser'); // using meteorhacks:npm package 2Picker.middleware(bodyParser());
You can use middlewares on sub routes as well.