Created
September 18, 2015 13:45
-
-
Save macedigital/6b71b9547dd4421d8724 to your computer and use it in GitHub Desktop.
Minimal example for using express-body-parser middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
var http = require('http'); | |
var server = http.createServer(app); | |
var xmlparser = require('express-xml-bodyparser'); | |
// fyi: it'd be better to attach the parser to wanted routes only | |
app.use(xmlparser()); | |
app.post('/xml', function(req, res, next) { | |
// req.body is an object, so we'll check if it has any (enumerable) properties | |
if (Object.keys(req.body).length) { | |
console.log('Parsed XML', req.body); | |
res.send('OK!'); | |
} else { | |
res.send('Not OK :('); | |
} | |
console.log('post body length', req.rawBody.length); // this is a string | |
return res.end(); | |
}); | |
server.listen(1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment