Yesod 1.4

Making a blog with Yesod, using Yesod 1.4 by Max Tagher. Source code for this screencast is available on Github.

Yesod 1.0

Yesod 1.0 Introductory Screencast from Michael Snoyman on Vimeo.

Older Screencasts

Some of the specific details shown here may be slightly out of date. The first 3 screencasts are for Yesod 0.5 and are mostly still accurate for Yesod 0.8. The Yesod book is up to date and a more canonical source of information. However, these screencasts still give a great overview in video form.

Yammer (Twitter clone)

Introduction to Yesod Web Framework 0.5

Hello World

Blog, part 1

Blog Tutorial - Part 1 - Yesod Web Framework 0.4.0 from Michael Snoyman on Vimeo.

Here's the source code:

{-# LANGUAGE TypeFamilies, QuasiQuotes, GeneralizedNewtypeDeriving #-}
    import Yesod
    import Database.Persist.Sqlite
    import Data.Time (Day)
    
    mkPersist [$persist|
    Entry
        title String
        day Day Desc
        content Html'
        deriving
    |]
    
    data Blog = Blog { pool :: Pool Connection }
    
    mkYesod "Blog" [$parseRoutes|
    / RootR GET
    /entry/#EntryId EntryR GET
    |]
    
    instance Yesod Blog where
        approot _ = "http://localhost:3000"
    
    instance YesodPersist Blog where
        type YesodDB Blog = SqliteReader
        runDB db = fmap pool getYesod>>= runSqlite db
    
    getRootR = do
        entries <- runDB $ select [] [EntryDayDesc]
        applyLayoutW $ do
            setTitle $ string "Yesod Blog Tutorial Homepage"
            addBody [$hamlet|
    %h1 Archive
    %ul
        $forall entries entry
            %li
                %a!href=@EntryR.fst.entry@ $entryTitle.snd.entry$
    |]
    
    getEntryR entryid = do
        entry <- runDB $ get404 entryid
        applyLayoutW $ do
            setTitle $ string $ entryTitle entry
            addBody [$hamlet|
    %h1 $entryTitle.entry$
    %h2 $show.entryDay.entry$
    $entryContent.entry$
    |]
    
    withBlog f = withSqlite "blog.db3" 8 $ \pool -> do
        flip runSqlite pool $ initialize (undefined :: Entry)
        f $ Blog pool
    
    main = withBlog $ basicHandler 3000

Blog, part 2

Blog Tutorial - Part 2 - Yesod Web Framework 0.4.0 from Michael Snoyman on Vimeo.

Here's the source code:

 
{-# LANGUAGE TypeFamilies, QuasiQuotes, GeneralizedNewtypeDeriving #-}
import Yesod
import Yesod.Helpers.Crud
import Database.Persist.Sqlite
import Data.Time (Day)
 
share2 mkToForm mkPersist [$persist|
Entry
    title String
    day JqueryDay Desc
    content NicHtml
    deriving
|]
 
instance Item Entry where
    itemTitle = entryTitle
 
data Blog = Blog { pool :: Pool Connection }
 
type EntryCrud = Crud Blog Entry
 
mkYesod "Blog" [$parseRoutes|
/ RootR GET
/entry/#EntryId EntryR GET
/admin AdminR EntryCrud defaultCrud
|]
 
instance Yesod Blog where
    approot _ = "http://localhost:3000"
 
instance YesodPersist Blog where
    type YesodDB Blog = SqliteReader
    runDB db = fmap pool getYesod>gt;>gt;= runSqlite db
 
getRootR = do
    entries gt; do
    flip runSqlite pool $ do
        initialize (undefined :: Entry)
    f $ Blog pool
 
main = withBlog $ basicHandler 3000