Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created October 4, 2012 18:00
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 snoyberg/3835314 to your computer and use it in GitHub Desktop.
Save snoyberg/3835314 to your computer and use it in GitHub Desktop.
Yesod routing with QuasiQuotes
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses,
TemplateHaskell, OverloadedStrings #-}
import Yesod
import Yesod.Routes.TH
data HelloWorld = HelloWorld
mkYesod "HelloWorld"
[ ResourceLeaf Resource
{ resourceName = "HomeR"
, resourcePieces = []
, resourceDispatch = Methods Nothing ["GET"]
}
, ResourceLeaf Resource
{ resourceName = "FibR"
, resourcePieces =
[ (True, Static "fib")
, (True, Dynamic "Int")
]
, resourceDispatch = Methods Nothing ["GET"]
}
]
instance Yesod HelloWorld
getHomeR :: Handler RepHtml
getHomeR = defaultLayout $ toWidget $ const ("Hello World" :: Html)
fibs :: [Int]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
getFibR :: Int -> Handler RepHtml
getFibR i = defaultLayout $ toWidget $ const $ toHtml $ fibs !! i
main :: IO ()
main = warpDebug 3000 HelloWorld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment