Skip to content

Instantly share code, notes, and snippets.

@timjb
Created May 8, 2015 12:20
Show Gist options
  • Select an option

  • Save timjb/d327e97a7111425985bd to your computer and use it in GitHub Desktop.

Select an option

Save timjb/d327e97a7111425985bd to your computer and use it in GitHub Desktop.
Nested routes using IsString
{-# LANGUAGE OverloadedStrings #-}
module NestedRoutesExample where
import Web.Routes.Nested
import Data.Text.Lazy as LT
import Network.Wai
import Data.Attoparsec.Text
router :: Application
router = route handlers
where
handlers = do
handleLit o
(Left $ get $ text "home")
Nothing
handleLit ("foo" </> "bar" </> o)
(Left $ get $ text "foobar") $ Just $
handleParse (p ("baz",double) </> o)
(\d -> Right $ get $ textOnly $ LT.pack (show d) `LT.append` " bazs")
Nothing
handleParse (p ("num",double) </> o)
(\d -> Right $ get $ textOnly $ LT.pack $ show d) $ Just $
handleLit ("bar" </> o)
(\d -> Left $ get $ text $ (LT.pack $ show d) `LT.append` " bars")
Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment