node package manager


fantasy-http ============


(Mostly) purely functional wrapper around Node's http module

Promise = require \fantasy-promises
{Readable} = require \stream
require \fantasy-streams
{serve, listen} = require \fantasy-http
main = listen 8000 serve ->
    Promise.of {status-code: 200 body: Readable.of "hello"}
$ curl localhost:8000
type Response = { body :: Readable Buffer
                , status-code :: Int
                , status :: String
                , headers :: Map String String }

The objects you'll be mostly playing with. Readable is anything with a .pipe Writable method; a Node steam will do. Note there's no distiction between a successful and failing response.

Takes a request handler (a function that turns requests into fantasy-promises for Responses) and creates a Node HTTP server with an appropriate (Request, Response) → () handler.

Creates an IO action to tell the server to listen on the port. Run it with .unsafePerform().

MIT. © 2013 Matt Brennan.