Skip to content

Instantly share code, notes, and snippets.

@calebcase
Created February 6, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebcase/674c05a85e03856102650d22be0f3522 to your computer and use it in GitHub Desktop.
Save calebcase/674c05a85e03856102650d22be0f3522 to your computer and use it in GitHub Desktop.

Let's go faster and just use the pre-built stuff in a docker container:

alias haskell='docker run -it --rm --user "$(id -u):$(id -g)" --net=host -v "$(pwd)":"/home/$USER" --workdir="/home/$USER" -e HOME="/home/$USER" haskell:8'

Pull down the most recent cabal index:

haskell cabal update

Install the scotty library:

haskell cabal install scotty

Setup our project (use defaults except the last question, say yes to the last one):

haskell cabal init

Create the main file to run the service:

Main.hs

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

import Data.Monoid (mconcat)

main = scotty 3000 $
    get "/:word" $ do
            beam <- param "word"
                    html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]

Run the service!

haskell cabal run

Curl the service!

curl 'localhost:3000'; echo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment