Difference between revisions of "HAppS tutorial"
Revision as of 22:06, 11 April 2007
Contents
- 1 Installing
- 2 Overview
- 3 First steps
- 3.1 How to build these examples
- 3.2 Getting the URL itself
- 3.3 Getting from a POST'd value )
- binary ( ).
Overview
The application model in HAppS is to help separate state, application logic, wire formats, protocols, and presentation layer:
State
State is just a haskell data type you define.
(FIXME: say a brief word about ACID).
How to build these examples
Cut'n'paste this into a file named Hello.hs and run
ghc --make Hello.hs -o hello to compile and then
./hello to execute the resulting binary.
Hello World
import HAppS helloWorld () () = respond "Hello World" main = stdHTTP -- stdHTTP takes a list of handlers to process. $ debugFilter : -- handler that prints all requests and responses on console noState : -- handler that defines application to have no persistent state [ h () GET $ ok $ val "Hello world" -- any request will return "Hello" ]" ]
Simple file serving
import HAppS main = stdHTTP $ debugFilter : -- we want to see debug messages in the console noState : -- our application has no state [ h [""] GET $ ok $ val "GETting root hello" , hs (Prefix ["s"]) GET $ basicFileServe staticPath ]
Note that to try this out with some static files you should create a directory named "static" in the directory where you are running the tutorial code, and put any files you wish to serve ins (Prefix ["s"]) GET $ basicFileServe staticPath ] isDot name = (take 1 (concat name) == ".")
hs let us consolidate these. SimpleHTTP2 defines basicFileServe as: ]
Saved stateReqURI [String] MyState where fromReqURI expr uri = do [val] <- fromReqURI (Prefix expr) uri fmap MySt $ mbRead"] GET $ ok $ \newVal () -> do put newVal; respond ("New value is " ++ show newVal) -- The first one is FromReqURI and the second one is FromMessage. ] plain $ val "Hello World" ,h "/setcookie" GET $ setsomecookie -- sets a cookie ,h "/showcookie" GET $ ok plain showallcookies ,h () () $ ok plain $ val "fallthrough" ] exampleHello () () = respond "Hello World" setsomecookie () () = do resp <- ok html )
Sessions
Sessions are much like
autoexpire state, and hook that expire event.
something can happen when state expiresxp