HOME

TheInfoList



OR:

Yesod (; he, יְסוֺד, "Foundation") is a
free and open-source Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
web framework A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build and ...
based on
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lang ...
for productive development of type-safe,
REST Rest or REST may refer to: Relief from activity * Sleep ** Bed rest * Kneeling * Lying (position) * Sitting * Squatting position Structural support * Structural support ** Rest (cue sports) ** Armrest ** Headrest ** Footrest Arts and entert ...
model based (where
URL A Uniform Resource Locator (URL), colloquially termed as a web address, is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifie ...
s identify resources, and
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, ...
methods identify transitions), high performance web applications, developed by Michael Snoyman et al. Yesod is based on templates, to generate instances for listed entities, and dynamic content process functions, through Template Haskell constructs to host
eDSL A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging f ...
content templates called QuasiQuotes, where the content is translated into code expressions by
metaprogramming Metaprogramming is a programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyze or transform other programs, and even modify itself ...
instructions. There are also web-like language
snippet A snippet is defined as a small piece of something; it may in more specific contexts refer to: * Sampling (music), the use of a short phrase of a recording as an element in a new piece of music * Snipets, (sic) a series of short TV interstitials p ...
templates that admit code expression interpolations, making them fully type-checked at compile-time. Yesod divides its functionality in separate libraries, so you may choose your functionality library of your choice.


MVC architecture


Controller


Server interface

Yesod uses a ''Web application interface''
API An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standa ...
, abbreviated ''WAI'', to isolate
servlet A Jakarta Servlet (formerly Java Servlet) is a Java software component that extends the capabilities of a server. Although servlets can respond to many types of requests, they most commonly implement web containers for hosting web application ...
s, aka web apps., from servers, with handlers for the server protocols CGI,
FastCGI FastCGI is a binary protocol A communication protocol is a system of rules that allows two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. The protocol defines the rules, s ...
,
SCGI The Simple Common Gateway Interface (SCGI) is a protocol for applications to interface with HTTP servers, as an alternative to the CGI protocol. It is similar to FastCGI but is designed to be easier to parse. Unlike CGI, it permits a long-running ...
, Warp, ''Launch'' (open as local ''URL'' to the default browser, closing the server when the window is closed),


The ''foundation'' type

See ref. Yesod requires a data type that instantiates the
controller Controller may refer to: Occupations * Controller or financial controller, or in government accounting comptroller, a senior accounting position * Controller, someone who performs agent handling in espionage * Air traffic controller, a person ...
classes. This is called the ''foundation'' type. In the example below, it is named "MyApp". The
REST Rest or REST may refer to: Relief from activity * Sleep ** Bed rest * Kneeling * Lying (position) * Sitting * Squatting position Structural support * Structural support ** Rest (cue sports) ** Armrest ** Headrest ** Footrest Arts and entert ...
model identifies a web resource with a web path. Here
REST Rest or REST may refer to: Relief from activity * Sleep ** Bed rest * Kneeling * Lying (position) * Sitting * Squatting position Structural support * Structural support ** Rest (cue sports) ** Armrest ** Headrest ** Footrest Arts and entert ...
resources are given names with an R suffix (like "HomeR") 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 (e.g. web resource names and handler names). 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" example based on a CGI server interface (The actual handler types have changed, but the philosophy remains): 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. for name composition of dispatch functions mkYesod "MyApp" / HomeR GET , instance Yesod MyApp -- indentation structured CSS template myStyle ::
ext Ext, ext or EXT may refer to: * Ext functor, used in the mathematical field of homological algebra * Ext (JavaScript library), a programming library used to build interactive web applications * Exeter Airport (IATA airport code), in Devon, England ...
→ CssUrl url myStyle paramStyle = .box border: 1px solid # , 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! There are # parameters: $if null params

Nothing to list $else