Last active
July 5, 2017 10:21
-
-
Save brynedwards/f27b9df1fa32a879a535fce0335f1039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --resolver lts-8.21 script | |
{-# LANGUAGE OverloadedStrings #-} | |
import Web.Spock | |
import Web.Spock.Config | |
import Control.Monad.IO.Class | |
import Data.Monoid | |
import Data.Text (Text) | |
main :: IO () | |
main = do | |
spockCfg <- defaultSpockCfg () PCNoDatabase () | |
runSpock 8080 (spock spockCfg app) | |
app :: SpockM () () () () | |
app = do | |
-- This will handle both /search/bla and /search/bla/ (with or without trailing slash) | |
get ("search" <//> var) $ \location -> | |
searchAction location Nothing | |
-- This will handle e.g. /search/bla/abc | |
get ("search" <//> var <//> var) $ \location terms -> | |
searchAction location (Just terms) | |
searchAction :: Text -> Maybe Text -> SpockAction () () () () | |
searchAction location Nothing = | |
text (mconcat ["Handle location ", location, ", no terms"]) | |
searchAction location (Just terms) = | |
text (mconcat ["Handle location ", location, " with terms ", terms]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment