Skip to content

Instantly share code, notes, and snippets.

@deckool
Created July 4, 2016 14:18
Show Gist options
  • Save deckool/73d1147956364fc167788c8d7854b81b to your computer and use it in GitHub Desktop.
Save deckool/73d1147956364fc167788c8d7854b81b to your computer and use it in GitHub Desktop.
small starter for maybe eventsource on snap framework
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Snap.Core
import Snap.Util.FileServe
import Snap.Http.Server
import Control.Monad.IO.Class
import qualified Data.ByteString.Char8 as BS
main :: IO ()
main = quickHttpServe site
site :: Snap ()
site = do
a <- getRequest
liftIO $ print a
routes a
where
routes a =
ifTop (writeBS "hello world") <|>
route [ ("foo", writeBS $ BS.pack (show a))
, ("echo/:echoparam", echoHandler)
] <|>
dir "static" (serveDirectory ".")
echoHandler :: Snap ()
echoHandler = do
param <- getParam "echoparam"
maybe (writeBS "must specify echo/param in URL")
writeBS param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment