Easy way to process post data in meteor.js?

I need to process some POST data in my meteor.js application, is there an easy way to do this?

Very simple, if it was a PHP application, I just need the $ _POST variable.

+4
source share
3 answers

Router Meteor

https://github.com/tmeasday/meteor-router#server-side-routing

Meteor.Router.add('/items/:id', 'POST', function(id) { // update Item Function return [200, 'ok']; }); 
+4
source

If you just want to intercept the GET and POST data, send the Meteor to have fun, you can do something similar on the server.

 if (Meteor.isServer) { var connect = Npm.require('connect'); var app = __meteor_bootstrap__.app; var post, get; app // parse the POST data .use(connect.bodyParser()) // parse the GET data .use(connect.query()) // intercept data and send continue .use(function(req, res, next) { post = req.body; get = req.query; return next(); }); Meteor.startup(function() { // do something with post and get variables }); } 

EDIT 11/01/13

As a result, I created an intelligent package for this (for myself). There is no documentation, but you can use it. https://github.com/johnnyfreeman/request-data

To get the foo request variable:

 RequestData.get('foo') // --> 'bar' RequestData.post('foo') // --> 'bar' 

Both methods will throw a Meteor.Error if the key is not found, so make sure you use wrap with try / catch if the variable is optional.

+1
source

You can use Meteor Iron Router , docs here , since the Router (as mentioned above) is deprecated and may stop functioning,

 Router.route('/items/:id', {where: 'server'}) .get(function () { this.response.end('get request\n'); }) .post(function () { this.response.end('post request\n'); }); 
0
source

All Articles