{-# LANGUAGE OverloadedStrings #-} {-# language DeriveAnyClass #-} {-# language ScopedTypeVariables #-} module Main (main) where import Web.Scotty import Network.Wai.Middleware.RequestLogger -- install wai-extra if you don't have this import Control.Exception (Exception(..)) import Control.Monad -- import Control.Monad.Trans import System.Random (newStdGen, randomRs) import Network.HTTP.Types (status302) import Data.Text.Lazy (pack) import Data.Text.Lazy.Encoding (decodeUtf8) import Data.String (fromString) import Data.Typeable (Typeable) data Err = Boom | UserAgentNotFound | NeverReached deriving (Show, Typeable, Exception) main :: IO () main = scotty 3000 $ do -- Add any WAI middleware, they are run top-down. middleware logStdoutDev -- get (function $ \req -> Just [("version", T.pack $ show $ httpVersion req)]) $ do -- v <- param "version" -- text v -- To demonstrate that routes are matched top-down. get "/" $ text "foobar" get "/" $ text "barfoo" -- Looking for a parameter in the path. Since the path pattern does not -- contain the parameter name 'p', the server responds with 500 Server Error. get "/foo_fail" $ do v <- pathParam "p" html $ mconcat ["