1. happs intro
  2. the missing happs documentation
  3. getting started with happs
  4. prerequisites
  5. cabal install me
  6. main
  7. url handling
  8. templates
  9. stringtemplate basics
  10. form post data
  11. querystring get data
  12. macid data
  13. changing the data model
  14. cron jobs
  15. thanks

Where it all begins: the function main

Have a look at main function at the core of this web application.

Two bits of code that should jump out at you as being important are "entrypoint :: Proxy AppState" and "controller".

The entrypoint function has to do with the HAppS state system, and we'll pospone learning about it for later.

To learn more about what the controller function is doing, , open this file in ghci: cd src; ghci Main.hs and have a look at these functions using ghci :info .

*Main> :i controller
controller :: [ServerPartT IO Response]
-- Defined at Controller.hs...
*Main> :i ServerPartT
newtype ServerPartT m a
= ServerPartT {unServerPartT :: Request -> WebT m a}
-- Defined in HAppS.Server.SimpleHTTP
instance [overlap ok] (Monad m) => Monad (ServerPartT m)
-- Defined in HAppS.Server.SimpleHTTP
*Main> :i WebT
newtype WebT m a = WebT {unWebT :: m (Result a)}
-- Defined in HAppS.Server.SimpleHTTP
instance [overlap ok] (Monad m) => Monad (WebT m)
-- Defined in HAppS.Server.SimpleHTTP
*Main> :i Result
data Result a
= NoHandle | Ok (Response -> Response) a | Escape Response
-- Defined in HAppS.Server.SimpleHTTP
instance [overlap ok] (Show a) => Show (Result a)
-- Defined in HAppS.Server.SimpleHTTP

The controller function is a list of ServerPartTs, which are basically handlers that accept an HTTP request and return a response. Well, ok... this is a bit obfuscated by the many types involved in the construction, and if you want to be pedantic it's probably a bit more complicated than that, but you don't need to understand all the details at this point. So, for the moment, just think about a ServerPartT as a wrapper over a function that takes an HTTP request and returns a response. We look at what is going on in the controller code in basic url handling, next.