]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/HelloWorld.hs
Added new example.
[Lucu.git] / examples / HelloWorld.hs
1 import Network
2 import Network.HTTP.Lucu
3
4 main :: IO ()
5 main = let config    = defaultConfig { cnfServerPort = PortNumber 9999 }
6            resources = mkResTree [ ( []
7                                    , helloWorld )
8
9                                  , ( ["urandom"]
10                                    , staticFile "/dev/urandom" )
11
12                                  , ( ["inc"]
13                                    , staticDir "/usr/include" )
14                                  ]
15        in
16          do putStrLn "Access http://localhost:9999/ with your browser."
17             runHttpd config resources
18
19
20 helloWorld :: ResourceDef
21 helloWorld
22     = ResourceDef {
23         resUsesNativeThread = False
24       , resIsGreedy         = False
25       , resGet
26           = Just $ do --time <- liftIO $ getClockTime
27                       --foundEntity (strongETag "abcde") time
28                       setContentType $ read "text/hello"
29                       outputChunk "Hello, "
30                       outputChunk "World!\n"
31       , resHead   = Nothing
32       , resPost
33           = Just $ do str1 <- inputChunk 3
34                       str2 <- inputChunk 3
35                       str3 <- inputChunk 3
36                       setContentType $ read "text/hello"
37                       output ("[" ++ str1 ++ " - " ++ str2 ++ "#" ++ str3 ++ "]")
38       , resPut    = Nothing
39       , resDelete = Nothing
40       }