Created
October 4, 2012 18:00
-
-
Save snoyberg/3835314 to your computer and use it in GitHub Desktop.
Yesod routing with QuasiQuotes
This file contains 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
{-# 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