Description
A type unsafe http library.
README.md
Teaser
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
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
.