Nov 23, 2010

Haskell for web development - web server for haskell

There are many web frameworks which use to develop web applications by using Haskell programming language. I will talk about "SNAP Framework".

Snap is a simple web development framework.It is very easy to install. To install this web framework you need to install GHC and Cabal-installer. Important thing is Cabal-installer must compatible with the GHC version. If both work correctly it will reduce lots of issues while installing the framework.

First you must update the cabal database by;
cabal update
Then try to install snap by;
cabal install snap-server

This will install all dependent packages which need by the snap-server. This may take some time to complete. If there is an error try to read and understand it. Most of the time those errors occur when the system is missing some dependent package and it should me manually installed. To get these packages try this website as possible as you can.
http://hackage.haskell.org/packages/archive/pkg-list.html

Then you need to install "expat library" which use in developments.
Use yum to install it.
yum install  expat-devel.i686

Now you should check if the path to the ~/.cabal/bin is in your path.
Then create a folder and do these steps.
mkdir test-snap
cd test-snap
snap init

This  will create a src directory and a file called test-snap.cabal. You may see three files in the src directory.

Now you can try to view this in your web browser. To do that, you need to run these command within the project root (inside the test-snap directory where you can see the.cabal file).

cabal install
test-snap 8000

Now you can visit the url http://localhost:8000/ to view he web page.

If you need to stop the server just press Ctrl+c.

Note:- When you are  creating a folder to build the project try to use a unique name like  [somethilng]-snap  or likewise. Because after the installation of the web site in will create an executable file in the ~/.cabal/bin, and that place is also available in the path variable.

1 comment:

  1. Hello, I just wanted to say that your blog has been really useful for me..
    I need all the help I can get, lol.. Thnx

    ReplyDelete

Your comments are always welcome ...