|
Subject: Re: Where to start about writing web/HTTP apps ? Newsgroups: gmane.comp.lang.haskell.cafe Date: 2005-09-12 19:54:23 GMT (3 years, 42 weeks, 2 days, 8 hours and 46 minutes ago) I will be launching (beta) a new commercial chat site written using Haskell and AJAX in the next month. The server is written on top of the HAppS library I made available at http://HappS.org. My general pattern for writing an application in this framework is write the server based on a wire-level spec where the server takes in XML/x-www-form-encoded/multipart-form-data and returns XML. Client side XSLT stylesheets then handle conversion of the XML to HTML. Here are the details if you are interested: 1. Write a web service spec as a reference for both client and server development. I use an informal language for this that relies on a mix of the reader understanding HTTP semantics and RelaxNG XML specs. POST /login ? {username {text},password{text},url{URL},captcha(text}} 200 session {attribute userId{text},attribute href {rel-URL}} Some text here describing other details that don't fit into the syntactic model described above. Server is assumed to handle any of application/x-www-form-urlencoded, multipart/form-data, or application/xml. Client is assumed to receive application/xml. Browser is assumed to handle XSL stylesheet PIs. (All conversion from XML to HTML is handled client side or on proxy using XSLT template) 2. Define Server State and state model data State = State {users::UserData} ...definition of user data... startState = State mzero addStateUser state user = .... 3. Define serialization for server state instance Show State where ... instance Read State where --- 4. Define exposed business logic addUser appCtx regInfo = if regGood then actionOk newState [] newUserInfo else qOk badRegInfo ... 5. define required wire formats for types --convert internal data type to XML instance ToElement NewUserInfo where toElement n = ... --convert posted data to internal data type instance FromMessage RegInfo where fromMessage msg = ... 6. define how busines logic maps to URLs ... a POST _ ["u"] = doXML addUser a GET "myapp.com" ("s":path) = fileServe mimeTypes "static" path myApp appCtx = let ?style=XSL "/s/style.xsl" in simpleHTTP a appCtx 7. define the app to execute run path host = do app <- startApp $ simpleConfig path startState confro serve host app return () main = run "appdir" "localhost:80" 8. put client side stuff (including style.xsl) in the "static" directory 9. install searchpath (see http://searchpath.org) 10 run it! $ searchPath ghc -o MyApp --internet http://searchpath.org/default.map src/MyApp.hs $ MyApp HAppS and the chat applications are still works in progress, but I have this running successfully internally already! - |
|
|