A type unsafe http library

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

BSD3 licensed by Jinjing Wang
Maintained by


Let's write a hello world app.

{-# LANGUAGE OverloadedStrings #-}

module Hello where

import Pipes (yield)

hello _ = pure (("HTTP/1.1 200 OK", []), yield "hello world\n")

Note, we are not importing any interface!

If we take a closer look at the type of hello:

Prelude Hello> :t hello 
  :: (Applicative f, Data.String.IsString a, Data.String.IsString t,
      Monad m) =>
    t2 -> f ((t, [t1]), Pipes.Internal.Proxy x' x () a m ())

This is a pure app!

Shall we run it?

{-# LANGUAGE OverloadedStrings #-}

module RunHello where

import Hello (hello)
import Network.HTTP.Pony.Serve (run)
import Network.HTTP.Pony.Transformer.HTTP (http)
import Pipes.Safe (runSafeT)

main :: IO ()
main = (runSafeT . run "localhost" "8080" . http) hello

Test it:

# the above files are mirrored in `./test`
runghc -isrc -itest test/RunHello.hs

# open another terminal
curl localhost:8080 -i

# output:

> HTTP/1.1 200 OK
> hello world

wow ~

Exercise: write a tcp cat


Revision history for http-pony -- 2016-09-22

  • First version. Released on an unsuspecting world. -- 2016-09-24

  • Add MonadSafe type for m, this enables resource safe request / response pipes. -- 2016-10-15

  • Gives the response producer a way, sending an empty bytestring, to explicitly shutdown the socket and return the control back to the producer. -- 2016-10-16

  • Handle the exception raised by trying to shutdown an already closed socket.
comments powered byDisqus