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

Safe HaskellNone

Snap.Snaplet.Router

Synopsis

Documentation

data RouterState Source

Constructors

RouterState 

Fields

_prefix :: Text
 

class Monad m => HasRouter m whereSource

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

initRouterSource

Arguments

:: Text

Prefix to add to paths.

-> SnapletInit b RouterState 

Snaplet initializer.

urlPathSource

Arguments

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

URL data type

-> m Path

Path of route

Returns the path for the given URL

urlPathParamsSource

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

redirectURLSource

Arguments

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

URL data type

-> m () 

Redirect to the path for the given URL

redirectURLParamsSource

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

routeWithSource

Arguments

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

routing function

-> m () 

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

routeWithDebugSource

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.

urlSpliceSource

Arguments

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

URL data type

-> m [Node] 

Returns the given URL as a Heist splice

urlParamsSpliceSource

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