0.1.1 • Published 12 years ago

http-stream v0.1.1

Weekly downloads
3
License
-
Repository
github
Last release
12 years ago

http-stream

Turn a HTTP server into a stream

Example

var chain = require("chain-stream")
    , pattern = require("mapleTree").pattern
    , HttpStream = require("..")

var server = chain(HttpStream().listen(8080))

server
    .filter(route("/"))
    .filter(method("GET"))
    .forEach(function (dup) {
        dup.end("hello world")
    })

server
    .filter(route("/json"))
    .filter(method("GET"))
    .forEach(function (dup) {
        dup.setHeader("content-type", "application/json")
        dup.end(JSON.stringify({ hello: "world" }))
    })

function route(uri) {
    var match = pattern(uri)

    return filter

    function filter(dup) {
        return match(dup.url)
    }
}

function method(methodName) {
    return filter

    function filter(dup) {
        return dup.method === methodName
    }
}

Installation

npm install http-stream

Contributors

  • Raynos

MIT Licenced