Skip to content

tellnes/body

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

body build status

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

MIT Licenced

Packages

No packages published

Languages

  • JavaScript 100.0%