Spock Intro – Minimal Web Framework
Spock is a slick little web framework in Haskell that builds off of Scotty’s legacy – although it apparently doesn’t share code any more.
It supports middleware, and a nice routing api.
For instance, to setup logging and static file serving, you just wire up two Wai middlewares.
1 2 3 4
Then the routes get built up (referencing the actual handler functions defined elsewhere)
1 2 3 4 5
Then connect the pieces up and run on port 3000.
I found myself repeating the specific ActionT type (the Spock route handler), so I type aliased it to be specific to my app (wrapping IO). This has the benefit of letting me change it in only one spot if/when I decide that I need a different monad transformer stack.
Then the actual handlers just have
HandlerM and the return value (mostly just unit)
There are a TON of helper functions to use in the context of a handler –
setHeader, etc, etc.
More and More
Spock claims to support sessions, database connection pooling and more, but I haven’t had a chance to dive into that integration.