Happstack
Published: 13:15, Thursday 14 July 2011
Notes
What's this? See my article about Notes.
View as plain text file.
install: cabal install happstack
helloworld:
module Main where
import Happstack.Server
main :: IO ()
main = simpleHTTP nullConf $ ok "Hello, World"
simpleHTTP :: (ToMessage a) => Conf -> ServerPartT IO a -> IO ()
data Conf, nullConf
ServerPartT
ok String
ok (toResponse String)
routing
ServerPartT:
msum [ mzero, ok "Hello", ok "Unreachable"]
tries all parts until one succeeds
mzero fails always
match dir:
[ dir "hello" $ ok "hello",
dir "goodbye" $ dir "moon" $ ok "goodye",
dirs "path/to" $ ok "sth"]
path:
[ dir "hello" $ path $ \s -> ok $ "Hello, " ++ s]
FromReqURI instance to match more stuff
match request method:
methodM
[ do methodM GET ok & ...,
do methodM POST ok $ ...,
dir "foo" $ do methodM GET ...
allow unconsumed path segments:
methodOnly
[do methodM [GET, HEAD]
ok $ "hey"
]
other routing filters:
nullDir, host, withHost, uriRest, anyPath, trailingSlash
html:
BlazeHtml, HSP, Hamlet, HStringTemplate, Heist, XSLT
request data:
look, if it fails -> mzero
always when processing post or put
decodeBody myPolicy
myPolicy = defaultBodyPolicy "/tmp/" 0 1000 1000
then look
forms should have enctype=multipart/form-data
file uploads:
lookFile
other: getDataFn, lookRead
cookies:
mkCookie, lookCookie, lookCookieValue, readCookieValue
Write a Comment
* These fields are mandatory.