encyclopegia.org

Yesod (web framework)

Yesod ( ; , "Foundation") is a web framework based on the programming language Haskell for productive development of type-safe, representational state transfer (REST) model based (where uniform resource locators (URLs) identify resources, and Hypertext Transfer Protocol (HTTP) methods identify transitions), high performance web applications, developed by Michael Snoyman, et al.[src] It is free and open-source software released under an MIT License.[src] Yesod is based on templates, to generate instances for listed entities, and dynamic content process functions, through Template Haskell constructs to host domain-specific language (eDSL) content templates called QuasiQuotes, where the content is translated into code expressions by metaprogramming instructions.[src] There are also web-like language snippet templates that admit code expression interpolations, making them fully type-checked at compile time.[src] Yesod divides its functions in separate libraries (database, html rendering, forms, etc.) so functions may used as needed.[src]

Yesod ( ; , "Foundation") is a web framework based on the programming language Haskell for productive development of type-safe, representational state transfer (REST) model based (where uniform resource locators (URLs) identify resources, and Hypertext Transfer Protocol (HTTP) methods identify transitions), high performance web applications, developed by Michael Snoyman, et al.[src] It is free and open-source software released under an MIT License.[src] Yesod is based on templates, to generate instances for listed entities, and dynamic content process functions, through Template Haskell constructs to host domain-specific language (eDSL) content templates called QuasiQuotes, where the content is translated into code expressions by metaprogramming instructions.[src] There are also web-like language snippet templates that admit code expression interpolations, making them fully type-checked at compile time.[src] Yesod divides its functions in separate libraries (database, html rendering, forms, etc.) so functions may used as needed.[src] {- file wai-cgi-hello.hs -} {-# LANGUAGE PackageImports, TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings #-} import "wai" Network.Wai import "wai-extra" Network.Wai.Handler.CGI (run) -- interchangeable WAI handler import "yesod" Yesod import "yesod-core" Yesod.Handler (getRequest) import "text" Data.Text (Text) import "shakespeare" Text.Cassius (Color(..), colorBlack) -- the Foundation type data MyApp = MyApp -- sitemap template, listing path, resource name and methods accepted -- `mkYesod` takes the foundation type name as param.[src] for name composition of dispatch functions mkYesod "MyApp" [parseRoutes| / HomeR GET |] instance Yesod MyApp -- indentation structured CSS template myStyle :: [Text] → CssUrl url myStyle paramStyle = [cassius| .box border: 1px solid #{boxColor} |] where boxColor = case paramStyle of ["high-contrast"] → colorBlack _ → Color 0 0 255 -- indentation structured HTML template myHtml :: [(Text, Text)] → HtmlUrl url myHtml params = [hamlet| Hello World![src] There are #{length params} parameters : $if null params Nothing to list $else $forall param #{fst param}: #{snd param} |] getHomeR :: Handler RepHtml getHomeR = do req >= run cgi test export REMOTE_ADDR=127.0.0.1 export REQUEST_METHOD=GET export PATH_INFO=/ export QUERY_STRING='p1=abc;p2=def;style=high-contrast' ./wai-cgi-hello -- given a MyApp foundation type mkYesod "MyApp" [parseRoutes| / HomeR -- no http methods stated: all methods accepted /blog BlogR GET POST -- the '#' prefix specify the path segment as a route handler parameter /article/#ArticleId ArticleR GET PUT -- the '*' prefix specify the parameter as a sequence of path pieces /branch/*Texts BranchR GET -- to simplify the grammar, compound types must use an alias, eg.[src] type Texts for [Text] |] Applying the previous template generates the following route constructors: data Route MyApp = HomeR -- referenced in templates as: @{HomeR} | BlogR -- in templates: @{BlogR} | ArticleR ArticleId -- in templates: @{ArticleR myArticleId} | BranchR Texts -- in templates: @{BranchR myBranchSegments} For every supported HTTP method a handler function must be created to match the dispatch names generated by mkYesod from the parseRoutes template, by prefixing the method name (or the prefix "handler" if no method stated) to the resource, as described (actual versions handler types have changed, but the philosophy remains): -- for "/ HomeR" -- no http methods stated ⇒ only one handler with prefix handler handlerHomeR :: HasReps t ⇒ Handler t -- for "/blog BlogR GET POST" getBlogR :: HasReps t ⇒ Handler t postBlogR :: HasReps t ⇒ Handler t -- for "/article/#ArticleId ArticleR GET PUT" getArticleR :: HasReps t ⇒ ArticleId → Handler t putArticleR :: HasReps t ⇒ ArticleId → Handler t -- a record for our form fields data Person = Person {personName :: Text, personAge :: Int, personLikings :: Maybe Text} -- the Form type has an extra parameter for an html snippet to be embedded, containing a CSRF token hidden field for security type Form sub master x = Html → MForm sub master (FormResult x, Widget) {- -- for messages in validation functions: @param master: yesod instance to use in renderMessage (return from handler's getYesod) @param languages: page languages to use in renderMessage -- optional defaults record: @param mbPersonDefaults: Just defaults_record, or Nothing for blank form -} personForm :: MyFoundationType → [Text] → Maybe Person → Form sub master Person {- aopt (optional field AForm component) for "Maybe" fields, areq (required fld AForm comp.) will insert the "required" attribute -} personForm master languages mbPersonDefaults = renderTable $ Person areq textField fldSettingsName mbNameDefault areq customPersonAgeField fldSettingsAge mbAgeDefault aopt textareaField fldSettingsLikings mbLikingsDefault where mbNameDefault = fmap personName mbPersonDefaults mbAgeDefault = fmap personAge mbPersonDefaults mbLikingsDefault = fmap personLikings mbPersonDefaults -- "fieldSettingsLabel" returns an initial fieldSettings record -- recently the "FieldSettings" record can be defined from a String label since it implements IsString fldSettingsName = (fieldSettingsLabel MsgName) {fsAttrs = [("maxlength","20")]} fldSettingsAge = fieldSettingsLabel MsgAge fldSettingsLikings = (fieldSettingsLabel MsgLikings) {fsAttrs = [("cols","40"),("rows","10")]} customPersonAgeField = check validateAge intField validateAge y | y toWidget [hamlet| $doctype 5 #{pageTitle} - My Site ^{headerTemplate} _{MsgArticleListTitle} $if null articles _{MsgSorryNoArticles} $else $forall art #{articleNumber art} .- #{articleTitle art} ^{footerTemplate} |] -- EBNF: identifier, {' ', parameter, '@', type}, ":", text with interpolations ArticleUnexistent param@Int64 : unexistent article #{param} message constructors are formed prepending "Msg" to the message label identifier.[src] the message datatype is formed appending "Message" to the foundation type name.[src] -- in code myMsg :: MyAppMessage -- datatype appending "Message" to the foundation type myMsg = MsgArticleUnexistent myArticleId -- constructor prepending "Msg" to the msg.[src] label -- in widget templates _{MsgArticleUnexistent myArticleId} Actual i18n support is missing from the app template.[src] The mkMessage "MyApp" messagesFolder isoLangDefault must be added to the "Foundation.hs" file to get the messages instantiated.[src] share [mkPersist sqlSettings, mkMigrate "migrateAll" -- generates the migration procedure with the specified name ] [persist| User -- table name and entity record type -- implicit autoincrement column "id" as primary key, typed UserId ident Text -- refers to db.[src] table column "ident"; -- generates a record field prefixing the table name as "userIdent" password Text Maybe -- Maybe indicates Nullable field UniqueUser ident -- unique constraint with space sep.[src] field sequence Email -- table name and entity record type -- implicit autoincrement column "id" as primary key, typed EmailId email Text user UserId -- foreign key by specifying other tables EntityField types verkey Text Maybe newlyAddedColumn Text "default='sometext'::character varying" -- sql level Default constraint UniqueEmail email -- unique constraint |] Esqueleto: is a haskell combinators layer to generate correct relational queries to persistent.[src] Example for persistent rawSQL and Esqueleto queries.[src] Yesod at Debian Yesod at Ubuntu[src]

23 sentences · 23 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Yesod (web framework)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/yesod-web-framework. Accessed 28 November 2026.

Chicago

"Yesod (web framework)." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/yesod-web-framework.

APA

encyclopegia.org. (2026). Yesod (web framework). Retrieved November 28, 2026, from https://encyclopegia.org/wiki/yesod-web-framework

Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

web server

stub · references available

web beacon

stub · references available

web syndication

stub · references available

software framework

stub · references available

Enterprise Objects Framework

stub · references available

web development

stub · references available

comparison of server-side web frameworks

stub · references available

ASP.NET MVC Framework

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1345094297 · 0.5 · snapshot enwiki-001345094297

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.