views:

162

answers:

4

I would like to try Haskell on a smallish project which should be well suited to it. I would like to use it as a backend to a small ajax application.

Haskell backend should be able to do authentication (basic, form, whatever, ...), keep track of user session (not much data there except for username) and to dispatch request to handlers based on uri and request type. It should also be able to serialize response to both xml and json format, depending on request parameter.

I suppose the handlers are ideally suited for Haskell, since the service is basically stateless, but I don't know where to start for the rest of the story.

Searching hackage didn't give me much hints.

Solution for pure haskell server would be prefered.

+1  A: 

Practical web programming in Haskell. There are a couple of modules you'll find useful, Text.XHtml and Network.CGI.

mdm
+2  A: 

I'm not sure how low-level you are trying to go. If you want to write your own server you could start from something like this: http://lstephen.wordpress.com/2008/02/14/a-simple-haskell-web-server/

Alternately, if you are looking for a pre-built framework you could try HApps: http://happs.org/

There is also a Ruby-On-Rails port. Turbinado or something.

Lastly, there are some getting started w/ CGI type tutorials. I've used this one: http://www.haskell.org/haskellwiki/Practical_web_programming_in_Haskell (It was also suggested in @mdm's answer)

Good luck!

Tim Perry
+2  A: 

I've recently written a production quality web service for internal use. I used the following packages:

  • CGI & FastCGI — for basic web server interfacing
  • UrlDisp — for URL based dispatching
  • HDBC & HDBC-mysql — for database access
  • hexpat — for XML parsing (some requests/responses were XML based)
  • parsec — for configuration file parsing (on the server side)
  • binary &/or cereal — for binary data parsing (some requests/responses were binary based) (though I'd probably use attoparsec now)

Also, for a different project, I'm also using:

  • xhtml — XHTML combintor library

None of these are the highest level components available for Haskell, but they are all quite workable and fairly complete. I avoided the higher-level abstractions since I needed to fit this into an existing larger system, and these packages work just like similar components I've used in other web service projects.

I ran the service as a fastCGI based handler for Apache2 w/mod_fcgid. This appears to be a reliable and efficient set up. I suppose a Haskell based server, compiled together with the service might be faster, but this was pretty reasonable with very little work. I got > 1,400 requests per second on a quad-cpu, 2.6GHz Linux server.

There are several Haskel pure servers. Most have their own APIs for your service code, though they are all pretty similar. Take a look at:

That's probably a lot to chew on. Let us know how it goes!

MtnViewMark
+1  A: 

There are some useful links in this question "What is the ecosystem for Haskell web development?"

Phil