snaplet-typed-sessions-0.5: Typed session snaplets and continuation-based programming for the Snap web framework

Safe HaskellSafe-Infered

Snap.Dialogues

Description

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.

Synopsis

Documentation

data DlgManager b v Source

A 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.

makeDlgManager :: Int -> IO (DlgManager b v)Source

Creates a new DlgManager with the given timeout in seconds for abandoned dialogues.

class HasDlgManager b v a | a -> b v whereSource

This type class identifies the location of the DlgManager in the session object. In order to use dialogues, your session type must be an instance of HasDlgManager.

Methods

getDlgManager :: a -> DlgManager b vSource

Extracts the DlgManager from a session object.

data Dlg m a Source

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.

Instances

MonadTrans Dlg 
Monad m => Monad (Dlg m) 
MonadIO m => MonadIO (Dlg m) 

type Page m = ByteString -> m ()Source

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.

showPage :: Monad m => Page m -> m a -> Dlg m aSource

Converts the combination of rendering and parsing a page into a step of a Dlg.

dialogue :: (HasTypedSession v t, HasDlgManager b v t) => ByteString -> Dlg (Handler b v) () -> Handler b v ()Source

The 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.