Package Exports
- body
- body/any
- body/form
- body/json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (body) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
body 
Body parsing
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
- Raynos