A minimum web dev DSL in Haskell http://github.com/nfjinjing/loli
|Latest on Hackage:||2011.6.24|
This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
A minimum web dev DSL
import Network.Loli import Hack.Handler.Happstack main = run . loli $ get "/" (text "loli power")
cabal update cabal install loli cabal install hack-handler-happstack -- copy and paste the above example to myapp.hs ghc --make myapp.hs ./myapp
-- use - instead of $ for clarity import MPS.Light ((-)) import Prelude hiding ((-)) import Network.Loli import Hack.Handler.Happstack main = run . loli - do get "/" - do -- something for a get request post "/" - do -- for a post request put "/" - do -- put .. delete "/" - do -- ..
get "/say/:user/:message" - do text . show =<< captures -- /say/jinjing/hello will output -- [("user","jinjing"),("message","hello")]
-- public serve, only allows `./src` public (Just ".") ["/src"]
-- treat .hs extension as text/plain mime "hs" "text/plain"
-- before takes a function of type (Env -> IO Env) before - \e -> do putStrLn "before called" return e -- after takes that of type (Response -> IO Response) after return
Use hack middleware
-- note both etag and lambda middleware are removed ... for somce ghc 7.0 compatability >< import Hack.Contrib.Middleware.ETag import Hack.Contrib.Middleware.Lambda middleware etag middleware lambda
Convert loli into a hack application
-- in Network.Loli.Engine loli :: Unit -> Application
- It’s recommended to use your own html combinator / template engine, loli’s template system is for completeness rather then usefulness… The author has removed the section on view from this readme. Examples can still be found in
src/Test/Test.hs. Try DIY with, e.g. moe. The template code will stay for, say, a few years, but will eventually fade away.
- Example view using custom html combinator (moe in this case)
- When inspecting the request, use
ReaderTmonad to get the
Hack.Environment, then use helper method defined in
Hack.Contrib.Requestto query it.
textare simply helper methods that update the state, i.e. setting the response body, content-type, etc.
- You do need to understand monad transformers to reach the full power of
- For mac users, use
GHC 6.12.1if you have trouble running the server.
- compile again …
- compatible with lastest mps
- use new hack-contrib
- use hackCache for performance
- no $ noise
- before / after filter
- On the fly router switcher
- safari display weird header
- Initial hackage release
- add template
- add local binding
- env and response are in reader and state monad respectively
- add route