body
Body parsing
Originally taken from npm-www
Example
var body = require("body")
var jsonBody = require("body/json")
var formBody = require("body/form")
var anyBody = require("body/any")
var http = require("http")
var sendJson = require("send-data/json")
http.createServer(function handleRequest(req, res) {
function send(err, body) {
sendJson(req, res, body)
}
if (req.url === "/body") {
body(req, res, send)
} else if (req.url === "/form") {
formBody(req, res, send)
} else if (req.url === "/json") {
jsonBody(req, res, send)
} else if (req.url === "/any") {
anyBody(req, res, send)
}
})
body
simply parses the request body and returns it in the callback. jsonBody
and formBody
call JSON.parse and querystring.parse respectively on the body.
anyBody will detect the content-type of the request and use the appropiate body method.
Installation
npm install body
Tests
npm test
Contributors
MIT Licenced