]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/HelloWorld.hs
Say good bye to the ugliness of "text" </> "plain".
[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          runHttpd config resources
17
18
19 helloWorld :: ResourceDef
20 helloWorld
21     = ResourceDef {
22         resUsesNativeThread = False
23       , resIsGreedy         = False
24       , resGet
25           = Just $ do --time <- liftIO $ getClockTime
26                       --foundEntity (strongETag "abcde") time
27                       setContentType $ read "text/hello"
28                       outputChunk "Hello, "
29                       outputChunk "World!\n"
30       , resHead   = Nothing
31       , resPost
32           = Just $ do str1 <- inputChunk 3
33                       str2 <- inputChunk 3
34                       str3 <- inputChunk 3
35                       setContentType $ read "text/hello"
36                       output ("[" ++ str1 ++ " - " ++ str2 ++ "#" ++ str3 ++ "]")
37       , resPut    = Nothing
38       , resDelete = Nothing
39       }