UrlDisp-0.1.7: Url dispatcher. Helps to retain friendly URLs in web applications.

Portabilityportable
Stabilityexperimental
Maintainerartyom.shalkhakov@gmail.com

Network.UrlDisp

Contents

Description

URL dispatching (routing) library, based on Sterling Clover's HVAC.

Synopsis

Types

Controller combinators

h :: MonadCGI 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.

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

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

(|?) :: (MonadCGI 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.

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 :: (MonadCGI m, Alternative m) => String -> m ()Source

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

param :: (MonadCGI 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.

Running UrlDisp

runUrlDispSource

Arguments

:: MonadCGI m 
=> String

path (hierarchical part of the URL)

-> UrlDisp m a 
-> m (Maybe a) 

Given path and a sequence of actions chained using combinators defined in controller API, run them in the CGI monad.

evalUrlDisp :: (MonadCGI m, MonadIO m) => UrlDisp m CGIResult -> m CGIResultSource

The same as runUrlDisp, but yields CGIResult. If URL dispatching failed, then a 404 not found error is returned.