networking

Haffle, a Haskell HTTP Server

When I program in my spare time, I usually do enough work to cover all of the interesting parts, and then abandon the project to move onto something new. I guess this is because I put more of a focus on the problem than the finished result.

Because of this, it’s something of a pleasant surprise that I am continuing to work on my Haskell HTTP server over a month after I started on it. I’ve decided on a name, Haffle, and I’ve just finished version 0.0.3. Haffle 0.0.3 can read POST variables and GET query strings, so it’s starting to become almost useful.

HTTP Server in Haskell

I’m a little dissatisfied with the libraries available for authoring web pages in Haskell. I want something that takes full advantage of Haskell’s do-notation to produce simple, readable code. Something like this:

main = httpServe 8080 $ do
    GET "/hello" ==> index
 
index :: Reader HttpRequest (HttpResponse -> IO HttpResponse)
index = do
    name <- param "name"
    setHeader "Content-Type" "text/plain"
    output "Hello "
    output name

I’m still a way from finishing it, but I’ve managed to create a HTTP request parser and a basic server. I’m aiming for a initial 0.0.1 release that will allow me to specify fixed outputs for any valid HTTP request:

main = httpServe 8080 (output "Hello World")

From there, I hope to add features with each release, until I have something usable. The code will be available under a MIT license.

Syndicate content