Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Last active Aug 29, 2015
Embed
What would you like to do?
Minimal multifile Yesod application
{-# 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
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module Application where
import Foundation
import Yesod
import Add
import Home
mkYesodDispatch "App" resourcesApp
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
module Foundation where
import Yesod
data App = App
mkYesodData "App" $(parseRoutesFile "routes")
instance Yesod App
{-# 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
|]
import Application
import Foundation
import Yesod
main :: IO ()
main = warp 3000 App
/ 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