Push XML Events To a NodeJS Server?
Problem
I need to Push Xml Events from some server to a NodeJS server.
I thought the best way to do so it to create a NodeJS based web service (WSDL, SOAP, XML... according to the standards) but i didn't find any module.
I thought about socket.io as well but i think it is relevant only when the communication includes a browser...
Any ideas?
Thanks
Solution
Well, the good news is Node gives you a great deal of flexibility, but doesn't always have the libraries to implement things like this.
So, the first question is does the other side already exist? As in, why XML?
Assuming it doesn't but you do want to use XML, two options include HTTP (REST) or TCP sockets, both of which can be trivally implemented in Node.
First, HTTP:
I'll be using express, though you can use another framework or just http if you prefer.
var express = require('express')
var app = express.createServer();
var notQuiteBasic = function(req, res, next) {
if (req.headers['Authentication']) {
req.authenticated = true;
};
next();
};
app.use(notQuiteBasic);
app.post('/xml', function(req, res) {
if (req.authenticated) {
processXml(req.body, function() {
res.send(200);
});
};
});
app.listen(8000);
And tcp:
var socket = require('socket');
var server = socket.createServer();
server.on('data', function (data) {
/* TODO: check envelope auth */
processXml(data);
});
server.listen(8222, '0.0.0.0');
Discussion
View additional discussion.