airship-0.4.2.0: A Webmachine-inspired HTTP library

Safe HaskellNone
LanguageHaskell2010

Airship.Route

Synopsis

Documentation

data Route Source

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.

data RoutingSpec m a Source

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

root :: Route Source

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

var :: Text -> Route Source

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 Source

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 Source

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 () Source

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.