Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

example

  • Loading branch information...
commit fd05a4df3ff4b1c2778a226de706e20c34e01673 1 parent 48efb13
@singpolyma authored
View
2  .gitignore
@@ -2,3 +2,5 @@ dist
*.o
*.hi
report.html
+example/Main
+example/Routes.hs
View
29 example/Application.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE OverloadedStrings #-} -- Whatever, it's just an example
+
+module Application where
+
+import Network.Wai
+import Network.HTTP.Types (ok200, notFound404)
+
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
+import qualified Data.ByteString.Lazy as LZ
+
+import Data.Monoid (mappend)
+
+textToUTF8 txt = LZ.fromChunks [T.encodeUtf8 txt]
+
+showUTF8 :: (Show a) => a -> LZ.ByteString
+showUTF8 = textToUTF8 . T.pack . show
+
+home _ = return $ responseLBS ok200 [("Content-Type", "text/plain")] "Hello World"
+
+test val _ = return $ responseLBS ok200 [("Content-Type", "text/plain")] (textToUTF8 val)
+
+on404 _ = return $ responseLBS notFound404 [("Content-Type", "text/plain")] "Not Found"
+
+test2 :: Integer -> Application
+test2 val _ = return $ responseLBS ok200 [("Content-Type", "text/plain")] (showUTF8 val)
+
+test3 val env = return $ responseLBS ok200 [("Content-Type", "text/plain")] (textToUTF8 val `mappend` "\n\n" `mappend` showUTF8 (pathInfo env))
View
13 example/Main.hs
@@ -0,0 +1,13 @@
+module Main where
+
+import Network.Wai
+import Network.Wai.Handler.Warp (run)
+import Network.Wai.Middleware.RequestLogger (logStdoutDev)
+
+import Network.Wai.Dispatch
+import Application
+import Routes
+
+main = do
+ putStrLn "Running..."
+ run 3000 (logStdoutDev $ dispatch on404 routes)
View
5 example/Makefile
@@ -0,0 +1,5 @@
+Main: Main.hs Application.hs Routes.hs
+ ghc $^
+
+Routes.hs: routes
+ ../dist/build/routeGenerator/routeGenerator $^ Application > $@
View
4 example/routes
@@ -0,0 +1,4 @@
+GET / => home
+GET /test/: => test
+GET /test2/: => test2
+GET /test3/:/* => test3
Please sign in to comment.
Something went wrong with that request. Please try again.