@@ -8,15 +8,14 @@ You want a minimal example? Here it is!
88
99> {-# LANGUAGE OverloadedStrings #-}
1010> import Network.Wai
11−> import Network.Wai.Enumerator (fromLBS)
12−> import Network.Wai.Handler.SimpleServer (run)
11+> import Network.Wai.Handler.Warp (run)
12+> import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance
1313>
1414> app :: Application
15−> app _ = return Response
16−> { status = status200
17−> , responseHeaders = [("Content-Type", "text/plain")]
18−> , responseBody = ResponseLBS "Hello, Web!"
19−> }
15+> app _ = return $ responseLBS
16+> status200
17+> [("Content-Type", "text/plain")]
18+> "Hello, Web!"
2019>
2120> main :: IO ()
2221> main = do
@@ -26,7 +25,7 @@ You want a minimal example? Here it is!
2625Put that code into a file named _hello.hs_ and install [wai] and
2726[wai-extra] from Hackage:
2827
29− cabal install wai wai-extra
28+ cabal install wai warp
3029
3130Run it:
3231
@@ -50,11 +49,10 @@ Now we redefine `responseBody` to refer to that file:
5049> app2 :: Application
5150> app2 _ = return index
5251>
53−> index = Response
54−> { status = status200
55−> , responseHeaders = [("Content-Type", "text/html")]
56−> , responseBody = ResponseFile "index.html"
57−> }
52+> index = ResponseFile
53+> status200
54+> [("Content-Type", "text/html")]
55+> "index.html"
5856
5957
6058Basic dispatching
@@ -74,17 +72,15 @@ different `Response`s:
7472> "/raw/" -> return plainIndex
7573> _ -> return notFound
7674>
77−> plainIndex = Response
78−> { status = status200
79−> , responseHeaders = [("Content-Type", "text/plain")]
80−> , responseBody = ResponseFile "index.html"
81−> }
75+> plainIndex = ResponseFile
76+> status200
77+> [("Content-Type", "text/plain")]
78+> "index.html"
8279>
83−> notFound = Response
84−> { status = status404
85−> , responseHeaders = [("Content-Type", "text/plain")]
86−> , responseBody = ResponseLBS "404 - Not Found"
87−> }
80+> notFound = responseLBS
81+> status404
82+> [("Content-Type", "text/plain")]
83+> "404 - Not Found"
8884
8985
9086Doing without overloaded strings
@@ -98,11 +94,10 @@ works without GHC extensions:
9894 import qualified Data.ByteString.Char8 as B8
9995 import qualified Data.ByteString.Lazy.Char8 as LB8
10096
101− notFound = Response
102− { status = Status404
103− , responseHeaders = [("Content-Type", B8.pack "text/plain")]
104− , responseBody = Right $ fromLBS $ LB8.pack "404 - Not Found"
105− }
97+ notFound = responseLBS
98+ status404
99+ [("Content-Type", B8.pack "text/plain")]
100+ (LB8.pack "404 - Not Found")
106101
107102
108103 [wai]: http://hackage.haskell.org/package/wai