Yesod (web framework)


Yesod is a web framework based on the programming language Haskell for productive development of type-safe, representational state transfer model based identify resources, and Hypertext Transfer Protocol, high performance web applications, developed by Michael Snoyman, et al. It is free and open-source software released under an MIT License.
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 content templates called QuasiQuotes, where the content is translated into code expressions by metaprogramming instructions.
There are also web-like language snippet templates that admit code expression interpolations, making them fully type-checked at compile time.
Yesod divides its functions in separate libraries so functions may used as needed.

MVC architecture

Yesod uses the model–view–controller software design pattern for its user interfaces.

Controller

Server interface

Yesod uses a Web application interface, a type of application programming interface, to isolate servlets, aka web apps., from servers, with handlers for the server protocols Common Gateway Interface, FastCGI, Simple Common Gateway Interface, Warp, Launch,

The ''foundation'' type

See ref. Yesod requires a data type that instantiates the model–view–controller classes. This is called the foundation type. In the example below, it is named "MyApp".
The REST model identifies a web resource with a web path. Here, REST resources are given names with an R suffix and are listed in a parseRoutes site map description template. From this list, route names and dispatch handler names are derived.
Yesod makes use of Template Haskell metaprogramming to generate code from templates at compile time, assuring that the names in the templates match and everything typechecks.
By inserting a mkYesod call, this will call Template Haskell primitives to generate the code corresponding to the route type members, and the instances of the dispatch controller classes as to dispatch GET calls to route HomeR to a routine named composing them both as "getHomeR", expecting an existing handler that matches the name.

Hello World

"Hello, World!" program example based on a Common Gateway Interface server interface :

import "wai" Network.Wai
import "wai-extra" Network.Wai.Handler.CGI -- interchangeable WAI handler
import "yesod" Yesod
import "yesod-core" Yesod.Handler
import "text" Data.Text
import "shakespeare" Text.Cassius
-- the Foundation type
data MyApp = MyApp
-- sitemap template, listing path, resource name and methods accepted
-- `mkYesod` takes the foundation type name as param. for name composition of dispatch functions
mkYesod "MyApp" → CssUrl url
myStyle paramStyle =
→ colorBlack
_ → Color 0 0 255
-- indentation structured HTML template
myHtml :: → HtmlUrl url
myHtml params =


Hello World! There are # parameters:
$if null params

Nothing to list
$else