Is REST and XML really this hard on Meteor?


#1

My Meteor app subscribes to an external service (superfeedr.com). It tracks HTML content changes on the sites I define in my subscription.

When that tracked content changes, superfeedr.com calls a REST POST API defined in my Meteor app and sends an XML payload.

I’m currently using Restivus, but it appears that only JSON is accepted (which works fine). Same for picker and simpleJSON.

What I want to do is grab the XML payload, run it through xml2json() to convert then process.

Is it possible to do this in Meteor? I’ve been searching and hacking for 2 days with nothing to show.

Thanks!


#2

I’m continuing to dive into this issue with Meteor 1.3 and I found an NPM middleware package (body-parser-xml) that works with Picker. It requires body-parser. Here is the require for that:

var _bodyParser = require('body-parser');
require('body-parser-xml')(_bodyParser);`

and I confirmed that a) meteor instantiates body-parser and b.) body-parser now has the xml() function to process xml

Next, to execute the middleware, you need to tell Picker to do so during it’s route processing (at least I think):

Picker.middleware(_bodyParser.xml());

What is supposed to happen is the XML will be made available via the request.body. However, I never see it.

Here is the completed Picker route inside the Meteor.startup function:

Picker.route('/api/imports2', function(req, res, next) {
    var _bodyParser = require('body-parser');
    require('body-parser-xml')(_bodyParser);

    Picker.middleware(_bodyParser.xml());

    var _xml = req.body;

    res.end(_xml);
});

Here is a curl example I’m sending:

curl -X POST -H "Content-Type: application/xml" -H "Accept: application/xml" -d '<run><log encoding="hexBinary">4142430A</log><result>0</result></duration></run>' http://localhost:3000/api/imports2/

All I receive is a request with an empty query object. No errors.

Using Charles, a web debugging proxy, all I see is the Meteor sockjs request with no indication of data.

Maybe it’s my CURL statement? Any advice?

I’m about to dump Meteor for this task and just write a node service. This should not be this hard…