Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Body parsing
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENCE
README.md
index.js
package.json

README.md

body build status

Body parsing

Example

var body = require("body")
    , jsonBody = body.json
    , formBody = body.form
    , anyBody = body.any
    , http = require("http")
    , sendJson = require("send-data").json

http.createServer(function handleRequest(req, res) {
    if (req.url === "/body") {
        body(req, res, function (err, body) {
            sendJson(req, res, body)
        })
    } else if (req.url === "/form") {
        formBody(req, res, function (err, body) {
            sendJson(req, res, body)
        })
    } else if (req.url === "/json") {
        jsonBody(req, res, function (err, body) {
            sendJson(req, res, body)
        })
    } else if (req.url === "/any") {
        anyBody(req, res, function (err, body) {
            sendJson(req, res, body)
        })
    }
})

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

MIT Licenced

Something went wrong with that request. Please try again.