snap-web-routes-0.5.1.0: Type safe URLs for Snap

Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.Router

Synopsis

Documentation

data RouterState Source

Constructors

RouterState 

Fields

_prefix :: Text
 

class Monad m => HasRouter m where Source

Instantiate this type class for Handler App App and Handler b RouterState so that the snaplet can find its state. An instance requires a type for URL m - being the URL data type you have defined - and an instance of getRouterState. Assuming your URL data type is called AppUrl, the instance for Handler b RouterState would be

instance HasRouter (Handler b RouterState) where
    type URL (Handler b RouterState) = AppUrl
    getRouterState = get

If the lens for the Router snaplet is router, your Handler App App instance would be

instance HasRouter (Handler App App) where
    type URL (Handler App App) = AppUrl
    getRouterState = with router get

Associated Types

type URL m Source

Instances

initRouter Source

Arguments

:: Text

Prefix to add to paths.

-> SnapletInit b RouterState 

Snaplet initializer.

urlPath Source

Arguments

:: (HasRouter m, PathInfo (URL m)) 
=> URL m

URL data type

-> m Path

Path of route

Returns the path for the given URL

urlPathParams Source

Arguments

:: (HasRouter m, PathInfo (URL m)) 
=> URL m

URL data type

-> [(Text, Maybe Text)]

Params

-> m Path

Path of route with params as query string

Returns the path with query string for the given URL and params

redirectURL Source

Arguments

:: (HasRouter m, MonadSnap m, PathInfo (URL m)) 
=> URL m

URL data type

-> m () 

Redirect to the path for the given URL

redirectURLParams Source

Arguments

:: (HasRouter m, MonadSnap m, PathInfo (URL m)) 
=> URL m

URL data type

-> [(Text, Maybe Text)]

Params

-> m () 

Redirect to the path for the given URL with params as query string

routeWith Source

Arguments

:: (PathInfo url, MonadSnap m) 
=> (url -> m ())

routing function

-> m () 

Given a routing function, routes matching requests or calls pass.

routeWithDebug Source

Arguments

:: (PathInfo url, MonadSnap m) 
=> (url -> m ())

routing function

-> m () 

Given a routing function, routes matching requests or returns debugging information. This is not suitable for production, but can be useful in seeing what paths are available or determining why a path isn't routing as expected.

urlSplice Source

Arguments

:: (HasRouter m, PathInfo (URL m)) 
=> URL m

URL data type

-> m [Node] 

Returns the given URL as a Heist splice

urlParamsSplice Source

Arguments

:: (HasRouter m, PathInfo (URL m)) 
=> URL m

URL data type

-> [(Text, Maybe Text)]

Params

-> m [Node] 

Returns the given URL as a Heist splice with query string for params