airship-0.6.0: A Webmachine-inspired HTTP library

Safe HaskellNone
LanguageHaskell2010

Airship.Route

Synopsis

Documentation

data Route #

Routes represent chunks of text used to match over URLs. You match hardcoded paths with string literals (and the -XOverloadedStrings extension), named variables with the var combinator, and wildcards with star.

Instances

Show Route # 

Methods

showsPrec :: Int -> Route -> ShowS #

show :: Route -> String #

showList :: [Route] -> ShowS #

IsString Route # 

Methods

fromString :: String -> Route #

Monoid Route # 

Methods

mempty :: Route #

mappend :: Route -> Route -> Route #

mconcat :: [Route] -> Route #

MonadWriter [(Route, Resource m)] (RoutingSpec m) # 

Methods

writer :: (a, [(Route, Resource m)]) -> RoutingSpec m a #

tell :: [(Route, Resource m)] -> RoutingSpec m () #

listen :: RoutingSpec m a -> RoutingSpec m (a, [(Route, Resource m)]) #

pass :: RoutingSpec m (a, [(Route, Resource m)] -> [(Route, Resource m)]) -> RoutingSpec m a #

data RoutingSpec m a #

Represents a fully-specified set of routes that map paths (represented as Routes) to Resources. RoutingSpecs are declared with do-notation, to wit:

   myRoutes :: RoutingSpec IO ()
   myRoutes = do
     root                                 #> myRootResource
     "blog" </> var "date" </> var "post" #> blogPostResource
     "about"                              #> aboutResource
     "anything" </> star                  #> wildcardResource

Instances

Monad (RoutingSpec m) # 

Methods

(>>=) :: RoutingSpec m a -> (a -> RoutingSpec m b) -> RoutingSpec m b #

(>>) :: RoutingSpec m a -> RoutingSpec m b -> RoutingSpec m b #

return :: a -> RoutingSpec m a #

fail :: String -> RoutingSpec m a #

Functor (RoutingSpec m) # 

Methods

fmap :: (a -> b) -> RoutingSpec m a -> RoutingSpec m b #

(<$) :: a -> RoutingSpec m b -> RoutingSpec m a #

Applicative (RoutingSpec m) # 

Methods

pure :: a -> RoutingSpec m a #

(<*>) :: RoutingSpec m (a -> b) -> RoutingSpec m a -> RoutingSpec m b #

(*>) :: RoutingSpec m a -> RoutingSpec m b -> RoutingSpec m b #

(<*) :: RoutingSpec m a -> RoutingSpec m b -> RoutingSpec m a #

MonadWriter [(Route, Resource m)] (RoutingSpec m) # 

Methods

writer :: (a, [(Route, Resource m)]) -> RoutingSpec m a #

tell :: [(Route, Resource m)] -> RoutingSpec m () #

listen :: RoutingSpec m a -> RoutingSpec m (a, [(Route, Resource m)]) #

pass :: RoutingSpec m (a, [(Route, Resource m)] -> [(Route, Resource m)]) -> RoutingSpec m a #

root :: Route #

Represents the root resource (/). This should usually be the first path declared in a RoutingSpec.

var :: Text -> Route #

Captures a named in a route and adds it to the routingParams hashmap under the provided Text value. For example,

   "blog" </> var "date" </> var "post"

will capture all URLs of the form /blog/$date/$post, and add date and post to the routingParams contained within the resource this route maps to.

star :: Route #

Captures a wildcard route. For example,

   "emcees" </> star

will match /emcees, /emcees/biggie, /emcees/earl/vince, and so on and so forth.

(</>) :: Route -> Route -> Route #

a </> b separates the path components a and b with a slash. This is actually just a synonym for mappend.

(#>) :: MonadWriter [(k, v)] m => k -> v -> m () #

The #> operator provides syntactic sugar for the construction of association lists. For example, the following assoc list:

    [("run", "jewels"), ("blue", "suede"), ("zion", "wolf")]

can be represented as such:

    execWriter $ do
      "run" #> "jewels"
      "blue" #> "suede"
      "zion" #> "wolf"

It used in RoutingSpec declarations to indicate that a particular Route maps to a given Resource, but can be used in many other places where association lists are expected, such as contentTypesProvided.