A simple HTTP server in Haskell

└─ 2017-11-12 • Reading time: ~1 minutes

I was recently looking for a way to create a very simple HTTP Server to serve static files in the current directory, in Haskell. The way we would do it in Python:

$ python -m SimpleHTTPServer 8000

That’s dead simple, exactly what I needed. It took me some time, but I finally found a very simple (and efficient) solution:

#! /usr/bin/env stack
  stack --resolver lts-9.12
        --install-ghc runghc
        --package wai-app-static
import Network.Wai.Handler.Warp (run)
import Network.Wai.Application.Static

main :: IO ()
main = run 8000 (staticApp (defaultFileServerSettings "."))

That’s it! And it’s using the super efficient warp HTTP server.