Nationwide Polyamorous Matrimony
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    fantasy-httppublic

    This package has been deprecated

    Author message:

    Use Oban instead

    fantasy-http

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

    Usage

    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"}
     
    main.unsafe-perform!
    $ curl localhost:8000
    hello

    API

    Response

    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.

    serve :: (Request → Promise Response) → Server

    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.

    listen :: Integer → Server → IO ()

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

    Licence

    MIT. © 2013 Matt Brennan.

    Keywords

    none

    install

    npm i fantasy-http

    Downloadslast 7 days

    2

    version

    0.0.0

    license

    MIT

    last publish

    collaborators

    • avatar