https://github.com/Meteor-Community-Packages/picker
Server Side Router for Meteor
https://github.com/Meteor-Community-Packages/picker
hacktoberfest meteor router
Last synced: 4 months ago
JSON representation
Server Side Router for Meteor
- Host: GitHub
- URL: https://github.com/Meteor-Community-Packages/picker
- Owner: Meteor-Community-Packages
- License: mit
- Fork: true (meteorhacks/picker)
- Created: 2020-06-28T08:55:38.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-05T12:49:53.000Z (about 1 year ago)
- Last Synced: 2024-05-05T22:22:14.885Z (about 1 year ago)
- Topics: hacktoberfest, meteor, router
- Language: JavaScript
- Homepage: https://atmospherejs.com/communitypackages/picker
- Size: 45.9 KB
- Stars: 16
- Watchers: 3
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
- awesome-meteor - communitypackages:picker - Server side router for Meteor 2. (Packages)
README
# 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.
## DEPRECATED
As of Meteor 3, Picker is deprecated as the functionality that has been provided by
it is now part of Meteor itself and the Express server that is baked into it.## Install
~~~
meteor add communitypackages:picker
~~~## Getting Started
~~~js
Picker.route('/post/:_id', function(params, req, res, next) {
const post = Posts.findOne(params._id);
res.end(post.content);
});~~~
* You can use Meteor APIs inside this callback (runs inside a Fiber)
* Route definitions are very similar to Iron Router and Express
* `req` is an instance of NodeJS [http.IncomingMessage](http://nodejs.org/api/http.html#http_class_http_incomingmessage)
* `res` is an instance of NodeJS [http.ServerResponse](http://nodejs.org/api/http.html#http_class_http_serverresponse)
* `next` is optional and call it, if you don't need to handle the current request## Filtering and Sub Routes
This is a 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`.
~~~js
const postRoutes = Picker.filter(function(req, res) {
// you can write any logic you want.
// but this callback does not run inside a fiber
// at the end, you must return either true or false
return req.method === "POST";
});postRoutes.route('/post/:id', function(params, req, res, next) {
// ...
});
~~~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.
~~~js
import bodyParser from 'body-parser';// Add two middleware calls. The first attempting to parse the request body as
// JSON data and the second as URL encoded data.
Picker.middleware( bodyParser.json() );
Picker.middleware( bodyParser.urlencoded( { extended: false } ) );
~~~You can use middlewares on sub routes as well.