Web application from the ground up

Hello, I am trying to implement a complete web application from the ground up, with the objective to convince myself and others that 1) it is possible, 2) it is powerful and 3) it is more expressive to do such a thing in Haskell. I managed to get to the point where I can handle users lifecycle with DB handling, and I have a CLI application. I have a World that stores Session objects, containing a "continuation" of possible functions to call. The problem I am facing now is how to handle (Fast)CGI requests, given that each request seems to be served by a dinstinct invocation of a function, and share the World between all connections. I have a vague idea that this could be handled by creating some CGIT transformed monad operating on a TVar World (that's what is hinted at on haskell wiki), but I am not sure how to tackle this. I asked this question on #haskell but had to leave too quickly. Some people there seems to think this is something very common that has been resolved over a hundred times. Once would be enough for me, and I would be very happy if someone could point me to the right direction or provide some sample code for this. Best regards, -- Arnaud Bailly, PhD OQube - Software Engineering http://www.oqube.com

Hi Arnaud,
Here's a simple counter program. I mount this to /ws/ with mod_scgi,
and can then do requests http://localhost/ws/ or
http://localhost/ws/?amount=19 (increment by 19 not 1).
http://hpaste.org/11033
I'm no expert but I'm also working on web applications in Haskell now.
If you are like me, not a big fan of monad transformers, the quick and
dirty way to share state between threads is through an MVar as
demonstrated above. Of course CGI is out of question as handles
requests in separate processes. So you would need FastCGI or SCGI or
(I guess that's the best) embedding a web server. Right now I am
playing with my own little pure Haskell SCGI implementation
(http://hpaste.org/11034) which does one forkIO per request, the
interface is:
runSCGI :: Timeout -> PortID -> CGIT IO CGIResult -> IO ()
forkProcess is only helpful to daemonize the program on UNIX.
Bests,
--A
On Thu, Oct 9, 2008 at 11:25 AM, Arnaud Bailly
Hello, I am trying to implement a complete web application from the ground up, with the objective to convince myself and others that 1) it is possible, 2) it is powerful and 3) it is more expressive to do such a thing in Haskell.
I managed to get to the point where I can handle users lifecycle with DB handling, and I have a CLI application. I have a World that stores Session objects, containing a "continuation" of possible functions to call.
The problem I am facing now is how to handle (Fast)CGI requests, given that each request seems to be served by a dinstinct invocation of a function, and share the World between all connections. I have a vague idea that this could be handled by creating some CGIT transformed monad operating on a TVar World (that's what is hinted at on haskell wiki), but I am not sure how to tackle this.
I asked this question on #haskell but had to leave too quickly. Some people there seems to think this is something very common that has been resolved over a hundred times. Once would be enough for me, and I would be very happy if someone could point me to the right direction or provide some sample code for this.
Best regards, -- Arnaud Bailly, PhD OQube - Software Engineering http://www.oqube.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Have you seen happstutorial.com?
thomas.
2008/10/9 Arnaud Bailly
Hello, I am trying to implement a complete web application from the ground up, with the objective to convince myself and others that 1) it is possible, 2) it is powerful and 3) it is more expressive to do such a thing in Haskell.
I managed to get to the point where I can handle users lifecycle with DB handling, and I have a CLI application. I have a World that stores Session objects, containing a "continuation" of possible functions to call.
The problem I am facing now is how to handle (Fast)CGI requests, given that each request seems to be served by a dinstinct invocation of a function, and share the World between all connections. I have a vague idea that this could be handled by creating some CGIT transformed monad operating on a TVar World (that's what is hinted at on haskell wiki), but I am not sure how to tackle this.
I asked this question on #haskell but had to leave too quickly. Some people there seems to think this is something very common that has been resolved over a hundred times. Once would be enough for me, and I would be very happy if someone could point me to the right direction or provide some sample code for this.
Best regards, -- Arnaud Bailly, PhD OQube - Software Engineering http://www.oqube.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

There's also newer material at
http://happstutorial.com:5002 that's in darcs but hasn't been packaged
for hackage.
2008/10/9 Thomas Hartman
Have you seen happstutorial.com?
thomas.
2008/10/9 Arnaud Bailly
: Hello, I am trying to implement a complete web application from the ground up, with the objective to convince myself and others that 1) it is possible, 2) it is powerful and 3) it is more expressive to do such a thing in Haskell.
I managed to get to the point where I can handle users lifecycle with DB handling, and I have a CLI application. I have a World that stores Session objects, containing a "continuation" of possible functions to call.
The problem I am facing now is how to handle (Fast)CGI requests, given that each request seems to be served by a dinstinct invocation of a function, and share the World between all connections. I have a vague idea that this could be handled by creating some CGIT transformed monad operating on a TVar World (that's what is hinted at on haskell wiki), but I am not sure how to tackle this.
I asked this question on #haskell but had to leave too quickly. Some people there seems to think this is something very common that has been resolved over a hundred times. Once would be enough for me, and I would be very happy if someone could point me to the right direction or provide some sample code for this.
Best regards, -- Arnaud Bailly, PhD OQube - Software Engineering http://www.oqube.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Arnaud Bailly, Share the world? *g* is a bit vague.. Fast CGI differs from CGI in one point: your application keeps running. Thus as long as the application is running you can use IORefs (bad for multithreading) MVars (thread safe) STM etc to keep track of your "world" state and of course you can share data on filesystem and in databases.. (you must lookup thread safety in the db lib documentations) I'd like to point you to a) HAppS-State lib providing state with ACID guarantees (-> hackage or happs.org or #happs on freenode) which already does a great job as long as your global data fits within RAM. b) You definitely should also have a look at WASH. This lib already has solved many common problems. It's mainly based on CGI. http://www.informatik.uni-freiburg.de/~thiemann/WASH/ But reading the examples should give an idea about how powerful web developement can be. I'm working on some topics as well. We also have a very low traffic web-dev mailinglist (haskell.org -> mailinglist ..) Have fun Marc Weber
participants (4)
-
Anton Tayanovskyy
-
Arnaud Bailly
-
Marc Weber
-
Thomas Hartman