8.0.0 • Published 9 years ago

send-data v8.0.0

Weekly downloads
1,516
License
-
Repository
github
Last release
9 years ago

send-data build status

send data through response

Originally taken from npm-www

Example

var send = require("send-data")
var sendJson = require("send-data/json")
var sendHtml = require("send-data/html")
var sendError = require("send-data/error")
var http = require("http")

http.createServer(function handleRequest(req, res) {
    if (req.url === "/send") {
        send(req, res, {
            body: "foo",
            statusCode: 202,
            headers: {
                bar: "baz"
            }
        })
    } else if (req.url === "/optional") {
        send(req, res, "foo")
    } else if (req.url === "/json") {
        sendJson(req, res, {
            body: {
                foo: "bar"
            },
            statusCode: 201
        })
    } else if (req.url === "/json/optional") {
        sendJson(req, res, {
            foo: "bar"
        })
    } else if (req.url === "/html") {
        sendHtml(req, res, {
            body: "<div>foo</div>",
            statusCode: 200,
            headers: {}
        })
    } else if (req.url === "/html/optional") {
        sendHtml(req, res, "<div>foo</div>")
    } else if (req.url === "/oops") {
        sendError(req, res, { body: new Error("OOPS") })
    }
}).listen(8080)

Installation

npm install send-data

Tests

npm test

Contributors

  • Raynos

MIT Licenced

8.0.0

9 years ago

7.0.0

9 years ago

6.0.0

9 years ago

5.0.0

9 years ago

4.0.1

9 years ago

3.3.4

9 years ago

3.3.3

10 years ago

3.3.2

10 years ago

3.3.1

10 years ago

3.3.0

10 years ago

3.2.5

10 years ago

3.2.4

10 years ago

3.2.3

10 years ago

3.2.2

10 years ago

3.2.1

10 years ago

3.2.0

10 years ago

3.1.2

10 years ago

3.1.1

10 years ago

3.0.7

11 years ago

3.0.6

11 years ago

3.0.5

11 years ago

3.0.4

11 years ago

3.0.3

11 years ago

2.2.2

11 years ago

3.0.1

11 years ago

2.2.1

11 years ago

2.1.1

11 years ago

1.1.3

11 years ago

2.0.1

11 years ago

1.1.2

11 years ago

1.1.1

11 years ago

1.0.1

11 years ago

0.1.0

12 years ago