yesod-0.4.1: Creation of type-safe, RESTful web applications.




The basic typeclass for a Yesod application.


Type classes

class Eq (Route a) => Yesod a whereSource

Define settings for a Yesod applications. The only required setting is approot; other than that, there are intelligent defaults.


approot :: a -> StringSource

An absolute URL to the root of the application. Do not include trailing slash.

If you want to be lazy, you can supply an empty string under the following conditions:

  • Your application is served from the root of the domain.
  • You do not use any features that require absolute URLs, such as Atom feeds and XML sitemaps.

encryptKey :: a -> IO KeySource

The encryption key to be used for encrypting client sessions.

clientSessionDuration :: a -> IntSource

Number of minutes before a client session times out. Defaults to 120 (2 hours).

errorHandler :: ErrorResponse -> GHandler sub a ChooseRepSource

Output error response pages.

defaultLayout :: PageContent (Route a) -> GHandler sub a ContentSource

Applies some form of layout to the contents of a page.

onRequest :: GHandler sub a ()Source

Gets called at the beginning of each request. Useful for logging.

urlRenderOverride :: a -> Route a -> Maybe StringSource

Override the rendering function for a particular URL. One use case for this is to offload static hosting to a different domain name to avoid sending cookies.

isAuthorized :: Route a -> GHandler s a AuthResultSource

Determine if a request is authorized or not.

Return Nothing is the request is authorized, Just a message if unauthorized. If authentication is required, you should use a redirect; the Auth helper provides this functionality automatically.

authRoute :: a -> Maybe (Route a)Source

The default route for authentication.

Used in particular by isAuthorized, but library users can do whatever they want with it.

class Eq (Route y) => YesodSite y whereSource

This class is automatically instantiated when you use the template haskell mkYesod function. You should never need to deal with it directly.


getSite :: Site (Route y) (Method -> Maybe (Handler y ChooseRep))Source

class Eq (Route s) => YesodSubSite s y whereSource

Same as YesodSite, but for subsites. Once again, users should not need to deal with it directly, as the mkYesodSub creates instances appropriately.


getSubSite :: Site (Route s) (Method -> Maybe (GHandler s y ChooseRep))Source


YesodAuth master => YesodSubSite Auth master 
YesodSubSite Static master 
(Yesod master, Item item, SinglePiece (Key item)) => YesodSubSite (Crud master item) master 


class YesodPersist y whereSource

Associated Types

type YesodDB y :: (* -> *) -> * -> *Source


runDB :: YesodDB y (GHandler sub y) a -> GHandler sub y aSource

get404 :: (PersistBackend (t m), PersistEntity val, Monad (t m), Failure ErrorResponse m, MonadTrans t) => Key val -> t m valSource


class YesodBreadcrumbs y whereSource

A type-safe, concise method of creating breadcrumbs for pages. For each resource, you declare the title of the page and the parent resource (if present).


breadcrumb :: Route y -> GHandler sub y (String, Maybe (Route y))Source

Returns the title and the parent resource, if available. If you return a Nothing, then this is considered a top-level page.

breadcrumbs :: YesodBreadcrumbs y => GHandler sub y (String, [(Route y, String)])Source

Gets the title of the current page and the hierarchy of parent pages, along with their respective titles.

Convenience functions



:: Yesod master 
=> String


-> Hamlet (Route master)


-> Hamlet (Route master)


-> GHandler sub master RepHtml 

Apply the default layout (defaultLayout) to the given title and body.



:: Yesod master 
=> String


-> Hamlet (Route master)


-> Hamlet (Route master)


-> Json 
-> GHandler sub master RepHtmlJson 

Provide both an HTML and JSON representation for a piece of data, using the default layout for the HTML output (defaultLayout).

maybeAuthorized :: Yesod a => Route a -> GHandler s a (Maybe (Route a))Source

Return the same URL if the user is authorized to see it.

Built on top of isAuthorized. This is useful for building page that only contain links to pages the user is allowed to see.


defaultErrorHandler :: Yesod y => ErrorResponse -> GHandler sub y ChooseRepSource

The default error handler for errorHandler.

Data types