This module provides an easy to use continuation-backed programming model for interactive web applications, called Snap Dialogues. A dialogue is a procedural description of an interaction with the user, which generally spans across many requests. Dialogues are specified in a monadic embedded domain-specific language.
- data DlgManager b v
- makeDlgManager :: Int -> IO (DlgManager b v)
- class HasDlgManager b v a | a -> b v where
- data Dlg m a
- type Page m = ByteString -> m ()
- showPage :: Monad m => Page m -> m a -> Dlg m a
- dialogue :: (HasTypedSession v t, HasDlgManager b v t) => ByteString -> Dlg (Handler b v) () -> Handler b v ()
DlgManager is user to keep track of ongoing dialogues with a
given user. One of them should be stored in the user's session.
The manager is parameterized on the base and value types for the
underlying request handling monad.
Creates a new
DlgManager with the given timeout in seconds for
A value of a
Dlg type represents a (possibly partial) dialogue
between the user and the application, producing a result of type
a. Dialogues can be composed using the monadic interface to
describe complex interactions.
A value of
Page type represents a way of rendering a page, given
the request URI for continuing the dialogue in the future.
Typically you will build pages using some kind of templating system
such as Heist.
Converts the combination of rendering and parsing a page into a
step of a
dialogue function builds a
Handler that handles a given
dialogue. The URLs of the dialog are of the form .../dlg-55555,
where dlg is the prefix (passed as a parameter) and 55555 is the
(numeric) dialogue ID. Requests to .../dlg create a new dialogue.
In general, this can be combined in normal ways with other routing
constructs, so long as request URIs of the above forms reach this
handler. When pages are served as part of a dialog, their relative
paths are passed on to later handlers, so images, stylesheets, etc.
can be served using
serveDirectory just as you normally would.