happstack-static-routing-0.7.0.1: Support for static URL routing with overlap detection for Happstack.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Happstack.StaticRouting

Description

Support for static routing tables in Happstack. The routing tables are order independent as long as:

  • if any two handlers overlap, one of them handles a more specific path than the other. The more specific handler is then tried first.

Routing tables are constructed from dir, path, remainingPath, choice, and param.

A routing table is compiled by using compile. The result is an overlap report, and a prefix tree that is used to efficiently dispatch requests by means of dispatch.

See the file src/Happstack/StaticRouting/Test.hs in the distribution for examples.

Synopsis

Documentation

data Route a Source #

Static routing tables consisting of handlers of type a.

Instances

Instances details
Functor Route Source # 
Instance details

Defined in Happstack.StaticRouting.Internal

Methods

fmap :: (a -> b) -> Route a -> Route b #

(<$) :: a -> Route b -> Route a #

compile :: ServerMonad m => Route (m r) -> Either String (m (Maybe r)) Source #

Compile routes or return overlap report. Returns 'Left e' in case of order-dependent overlap between handlers, where e describes the overlap. Returns 'Right h', where h is a compiled handler that returns Nothing in case no matching handler was found, otherwise 'Just response'.

choice :: [Route a] -> Route a Source #

Combine several route alternatives into one.

dir :: String -> Route a -> Route a Source #

Pop a path element if it matches the given string.

param :: Route a -> Route a Source #

Pop a path element, and store it to use with handler

path :: forall m hm h r r'. Path m hm h r => Method -> (m r -> hm r') -> h -> Route (hm r') Source #

Expect the given method, and exactly n more segments, where n is the arity of the handler.

class Path m hm h r | h -> m r Source #

Support for varying number of arguments to path handlers.

Minimal complete definition

pathHandler, arity, canBeApplied

Instances

Instances details
Path m hm (m r) r Source # 
Instance details

Defined in Happstack.StaticRouting.Internal

Methods

pathHandler :: (m r -> hm r') -> m r -> hm r'

arity :: m r -> Int

canBeApplied :: m r -> [String] -> Bool

(FromReqURI v, ServerMonad hm, Path m hm h r) => Path m hm (v -> h) r Source # 
Instance details

Defined in Happstack.StaticRouting.Internal

Methods

pathHandler :: (m r -> hm r') -> (v -> h) -> hm r'

arity :: (v -> h) -> Int

canBeApplied :: (v -> h) -> [String] -> Bool

remainingPath :: Method -> h -> Route h Source #

Expect zero or more segments.