send-data

send data through response

33 个版本
安装
npm install send-data
yarn add send-data
pnpm add send-data
bun add send-data
README

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 2015-10-20
7.0.0 2015-04-01
6.0.0 2015-02-11
5.0.0 2015-01-20
4.0.1 2015-01-20
3.3.4 2015-01-06
3.3.3 2014-08-19
3.3.2 2014-08-10
3.3.1 2014-07-30
3.3.0 2014-07-29
3.2.5 2014-07-15
3.2.4 2014-06-08
3.2.3 2014-06-08
3.2.2 2014-06-08
3.2.1 2014-06-08
3.2.0 2014-06-08
3.1.2 2013-11-10
3.1.1 2013-11-10
3.0.7 2013-10-02
3.0.6 2013-08-23
3.0.5 2013-08-23
3.0.4 2013-08-08
3.0.3 2013-08-07
3.0.1 2013-08-07
2.2.2 2013-08-07
2.2.1 2013-08-01
2.1.1 2013-07-07
2.0.1 2013-07-06
1.1.3 2013-07-06
1.1.2 2013-05-09
1.1.1 2013-05-08
1.0.1 2013-04-24
0.1.0 2012-09-23