Spock

Another Haskell web framework for rapid development

http://www.spock.li

Version on this page:0.8.1.0
LTS Haskell 21.25:0.14.0.0
Stackage Nightly 2023-06-21:0.14.0.0
Latest on Hackage:0.14.0.0

See all snapshots Spock appears in

BSD-3-Clause licensed and maintained by Alexander Thiemann
This version can be pinned in stack with:Spock-0.8.1.0@sha256:d489e2a5d60f105f7f8511a149c2a361de31f7cf450ad6dbad2fbece885735bb,4299

Module documentation for 0.8.1.0

Spock

Build Status

Hackage Deps

For more information and tutorials, visit spock.li

Intro

Hackage: Spock Tutorial: Spock Tutorial

Another Haskell web framework for rapid development: This toolbox provides everything you need to get a quick start into web hacking with haskell:

  • fast routing (both typesafe and “untyped”)
  • middleware
  • json
  • sessions
  • cookies
  • database helper
  • csrf-protection

Benchmarks:

Usage (Typesafe, recommended)

{-# LANGUAGE OverloadedStrings #-}
import Web.Spock

import qualified Data.Text as T

main =
    runSpock 3000 $ spockT id $
    do get ("echo" <//> var) $ \something ->
        text $ T.concat ["Echo: ", something]

(read more at Type-safe routing in Spock)

Usage (Simple)

{-# LANGUAGE OverloadedStrings #-}
import Web.Spock.Simple

import qualified Data.Text as T

main =
    runSpock 3000 $ spockT id $
    do get ("echo" <//> ":something") $
        do Just something <- param "something"
           text $ T.concat ["Echo: ", something]
       get ("regex" <//> "{number:^[0-9]+$}") $
        do Just number <- param "number"
           text $ T.concat ["Just a number: ", number]

Install

  • Using cabal: cabal install Spock
  • From Source: git clone https://github.com/agrafix/Spock.git && cd Spock && cabal install

Candy

Extensions

The following Spock extensions exist:

Works well with Spock

Example Projects

Talks

Companies / Projects using Spock

Notes

Since version 0.7.0.0 Spock supports typesafe routing. If you wish to continue using the untyped version of Spock you can Use Web.Spock.Simple. The implementation of the routing is implemented in a separate haskell package called reroute.

Since version 0.5.0.0 Spock is no longer built on top of scotty. The design and interface is still influenced by scotty, but the internal implementation differs from scotty’s.

Thanks to

  • Tim Baumann Github (lot’s of help with typesafe routing)
  • Tom Nielsen Github (much feedback and small improvements)