urldisp-happstack-0.1: Simple, declarative, expressive URL routing -- on happstack.

Happstack.UrlDisp

Contents

Synopsis

Run the monad

runUrlDisp :: ServerMonad m => UrlDisp m a -> m aSource

Unpacks a UrlDisp into a plain old ServerMonad. Used as a top-level wrapper.

Verbose API

path :: (MonadState UrlS m, Alternative m) => String -> m ()Source

Filters on and consumes the next element of the url path. path "str" will match requests whose next path element is "str" Consumption of the path element backtracks on failure.

meth :: (ServerMonad m, MonadPlus m) => String -> m ()Source

Filters on the request method. meth "GET" will match requests made using get.

param :: (ServerMonad m, Alternative m) => (String, String) -> m ()Source

Filters on any parameter (via put or get). param ("cmd", "foo") will match on ?cmd=foo

takePath :: (MonadState UrlS m, Alternative m) => m StringSource

Combinator that consumes the next element of the path and passes it as an unparsed string into the following lambda expression. h takePath \x -> output (x++"99") will match on "/12" and output "1299" Consumption of the path element backtracks on failure.

readPath :: (Read a, MonadState UrlS m, Alternative m) => m aSource

Matches and consumes the next element of the path if that element can be successfully read as the proper type. The parsed element is returned.

endPath :: (MonadState UrlS m, Alternative m) => m ()Source

Only matches if the remaining path is empty.

getInput :: (ServerMonad f, Alternative f) => String -> f StringSource

Returns a string representation of a parameter, if available. Otherwise fails.

getInputMay :: (ServerMonad f, Alternative f) => String -> f (Maybe String)Source

Returns Just a string representation of a parameter, or Nothing.

Infix API

h :: ServerMonad m => m ()Source

A null CGI action, used to begin a string of path combinators

(|/) :: (MonadState UrlS m, Alternative m) => m a -> String -> m ()Source

Combinator that filters on and consumes the next element of the url path. h |/ "dir" |/ "subdir" will match "/dir/subdir". Consumtion of the path element backtracks on failure.

(|//) :: (ServerMonad m, MonadPlus m) => m a -> String -> m ()Source

Combinator that filters on the request method. h |// "GET" will match requests made using get.

(|?) :: (ServerMonad m, Alternative m) => m a -> (String, String) -> m ()Source

Combinator that filters on any parameter (via put or get). h |? ("cmd","foo") will match on ?cmd=foo

(|\) :: (Read x, MonadState UrlS m, Alternative m) => m a -> (x -> m b) -> m bSource

Combinator that matches and consumes the next element of the path if path element can be successfully read as the proper type and passed to the following lambda expression. h |\ \x -> output (x + (1.5::Float)) will match on "/12" and output "13.5". Consumption of the path element backtracks on failure.

(|\\) :: (MonadState UrlS m, Alternative m) => m a -> (String -> m b) -> m bSource

Combinator that consumes the next element of the path and passes it as an unparsed string into the following lambda expression. h |\\ \x -> output (x++"99") will match on "/12" and output "1299" Consumtion of the path element backtracks on failure.

(|.) :: (MonadState UrlS m, Alternative m) => m a -> m b -> m bSource

Combinator that only matches if the remaining path is empty.

Lifted catch