Last active
August 29, 2015 14:11
-
-
Save snoyberg/07d61088a1376ff3deab to your computer and use it in GitHub Desktop.
Minimal multifile Yesod application
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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
module Add where | |
import Foundation | |
import Yesod | |
getAddR :: Int -> Int -> Handler TypedContent | |
getAddR x y = selectRep $ do | |
provideRep $ defaultLayout $ do | |
setTitle "Addition" | |
[whamlet|#{x} + #{y} = #{z}|] | |
provideJson $ object ["result" .= z] | |
where | |
z = x + y |
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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE ViewPatterns #-} | |
module Application where | |
import Foundation | |
import Yesod | |
import Add | |
import Home | |
mkYesodDispatch "App" resourcesApp |
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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE ViewPatterns #-} | |
module Foundation where | |
import Yesod | |
data App = App | |
mkYesodData "App" $(parseRoutesFile "routes") | |
instance Yesod App |
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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
module Home where | |
import Foundation | |
import Yesod | |
getHomeR :: Handler Html | |
getHomeR = defaultLayout $ do | |
setTitle "Minimal Multifile" | |
[whamlet| | |
<p> | |
<a href=@{AddR 5 7}>HTML addition | |
<p> | |
<a href=@{AddR 5 7}?_accept=application/json>JSON addition | |
|] |
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
import Application | |
import Foundation | |
import Yesod | |
main :: IO () | |
main = warp 3000 App |
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
/ HomeR GET | |
/add/#Int/#Int AddR GET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment