on master help sign in
Updated README.lhs (and README.md)
commitebcfa5cbe4020eccd06496bad8270ecddd5e197d authorMichael Snoyman <michael@snoyman.com> dateTue 11 Jan 2011, 20:07 (16 years ago) parent709258d
2 files changed+46−56
README.lhs+23−28 README.md+23−28
README.lhs+23−28
@@ -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
README.md+23−28
@@ -9,15 +9,14 @@ You want a minimal example? Here it is!
99
1010 {-# LANGUAGE OverloadedStrings #-}
1111 import Network.Wai
12− import Network.Wai.Enumerator (fromLBS)
13− import Network.Wai.Handler.SimpleServer (run)
12+ import Network.Wai.Handler.Warp (run)
13+ import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance
1414
1515 app :: Application
16− app _ = return Response
17− { status = status200
18− , responseHeaders = [("Content-Type", "text/plain")]
19− , responseBody = ResponseLBS "Hello, Web!"
20− }
16+ app _ = return $ responseLBS
17+ status200
18+ [("Content-Type", "text/plain")]
19+ "Hello, Web!"
2120
2221 main :: IO ()
2322 main = do
@@ -26,7 +25,7 @@ You want a minimal example? Here it is!
2625
2726Put that code into a file named _hello.hs_ and install [wai] and [wai-extra] from Hackage:
2827
29− cabal install wai wai-extra
28+ cabal install wai warp
3029
3130Run it:
3231
@@ -49,11 +48,10 @@ Now we redefine `responseBody` to refer to that file:
4948 app2 :: Application
5049 app2 _ = return index
5150
52− index = Response
53− { status = status200
54− , responseHeaders = [("Content-Type", "text/html")]
55− , responseBody = ResponseFile "index.html"
56− }
51+ index = ResponseFile
52+ status200
53+ [("Content-Type", "text/html")]
54+ "index.html"
5755
5856
5957Basic dispatching
@@ -72,17 +70,15 @@ Depending on the path info provided with each `Request` we can serve different `
7270 "/raw/" -> return plainIndex
7371 _ -> return notFound
7472
75− plainIndex = Response
76− { status = status200
77− , responseHeaders = [("Content-Type", "text/plain")]
78− , responseBody = ResponseFile "index.html"
79− }
73+ plainIndex = ResponseFile
74+ status200
75+ [("Content-Type", "text/plain")]
76+ "index.html"
8077
81− notFound = Response
82− { status = status404
83− , responseHeaders = [("Content-Type", "text/plain")]
84− , responseBody = ResponseLBS "404 - Not Found"
85− }
78+ notFound = responseLBS
79+ status404
80+ [("Content-Type", "text/plain")]
81+ "404 - Not Found"
8682
8783
8884Doing without overloaded strings
@@ -93,11 +89,10 @@ For the sake of efficiency, WAI uses the [bytestring] package. We used GHCs [ov
9389 import qualified Data.ByteString.Char8 as B8
9490 import qualified Data.ByteString.Lazy.Char8 as LB8
9591
96− notFound = Response
97− { status = Status404
98− , responseHeaders = [("Content-Type", B8.pack "text/plain")]
99− , responseBody = Right $ fromLBS $ LB8.pack "404 - Not Found"
100− }
92+ notFound = responseLBS
93+ status404
94+ [("Content-Type", B8.pack "text/plain")]
95+ (LB8.pack "404 - Not Found")
10196
10297
10398 [wai]: http://hackage.haskell.org/package/wai