airship-0.9.4: 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.

Instances
Show Route Source # 
Instance details

Defined in Airship.Internal.Route

Methods

showsPrec :: Int -> Route -> ShowS #

show :: Route -> String #

showList :: [Route] -> ShowS #

IsString Route Source # 
Instance details

Defined in Airship.Internal.Route

Methods

fromString :: String -> Route #

Semigroup Route Source # 
Instance details

Defined in Airship.Internal.Route

Methods

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

sconcat :: NonEmpty Route -> Route #

stimes :: Integral b => b -> Route -> Route #

Monoid Route Source # 
Instance details

Defined in Airship.Internal.Route

Methods

mempty :: Route #

mappend :: Route -> Route -> Route #

mconcat :: [Route] -> Route #

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
Instances
Monad (RoutingSpec m) Source # 
Instance details

Defined in Airship.Internal.Route

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) Source # 
Instance details

Defined in Airship.Internal.Route

Methods

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

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

Applicative (RoutingSpec m) Source # 
Instance details

Defined in Airship.Internal.Route

Methods

pure :: a -> RoutingSpec m a #

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

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

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

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

MonadWriter [(ByteString, RouteLeaf m)] (RoutingSpec m) Source # 
Instance details

Defined in Airship.Internal.Route

Methods

writer :: (a, [(ByteString, RouteLeaf m)]) -> RoutingSpec m a #

tell :: [(ByteString, RouteLeaf m)] -> RoutingSpec m () #

listen :: RoutingSpec m a -> RoutingSpec m (a, [(ByteString, RouteLeaf m)]) #

pass :: RoutingSpec m (a, [(ByteString, RouteLeaf m)] -> [(ByteString, RouteLeaf m)]) -> RoutingSpec m a #

data RouteLeaf m Source #

Instances
MonadWriter [(ByteString, RouteLeaf m)] (RoutingSpec m) Source # 
Instance details

Defined in Airship.Internal.Route

Methods

writer :: (a, [(ByteString, RouteLeaf m)]) -> RoutingSpec m a #

tell :: [(ByteString, RouteLeaf m)] -> RoutingSpec m () #

listen :: RoutingSpec m a -> RoutingSpec m (a, [(ByteString, RouteLeaf m)]) #

pass :: RoutingSpec m (a, [(ByteString, RouteLeaf m)] -> [(ByteString, RouteLeaf m)]) -> RoutingSpec m a #

data Trie a #

A map from ByteStrings to a. For all the generic functions, note that tries are strict in the Maybe but not in a.

The Monad instance is strange. If a key k1 is a prefix of other keys, then results from binding the value at k1 will override values from longer keys when they collide. If this is useful for anything, or if there's a more sensible instance, I'd be curious to know.

Instances
Monad Trie 
Instance details

Defined in Data.Trie.Internal

Methods

(>>=) :: Trie a -> (a -> Trie b) -> Trie b #

(>>) :: Trie a -> Trie b -> Trie b #

return :: a -> Trie a #

fail :: String -> Trie a #

Functor Trie 
Instance details

Defined in Data.Trie.Internal

Methods

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

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

Applicative Trie 
Instance details

Defined in Data.Trie.Internal

Methods

pure :: a -> Trie a #

(<*>) :: Trie (a -> b) -> Trie a -> Trie b #

liftA2 :: (a -> b -> c) -> Trie a -> Trie b -> Trie c #

(*>) :: Trie a -> Trie b -> Trie b #

(<*) :: Trie a -> Trie b -> Trie a #

Foldable Trie 
Instance details

Defined in Data.Trie.Internal

Methods

fold :: Monoid m => Trie m -> m #

foldMap :: Monoid m => (a -> m) -> Trie a -> m #

foldr :: (a -> b -> b) -> b -> Trie a -> b #

foldr' :: (a -> b -> b) -> b -> Trie a -> b #

foldl :: (b -> a -> b) -> b -> Trie a -> b #

foldl' :: (b -> a -> b) -> b -> Trie a -> b #

foldr1 :: (a -> a -> a) -> Trie a -> a #

foldl1 :: (a -> a -> a) -> Trie a -> a #

toList :: Trie a -> [a] #

null :: Trie a -> Bool #

length :: Trie a -> Int #

elem :: Eq a => a -> Trie a -> Bool #

maximum :: Ord a => Trie a -> a #

minimum :: Ord a => Trie a -> a #

sum :: Num a => Trie a -> a #

product :: Num a => Trie a -> a #

Traversable Trie 
Instance details

Defined in Data.Trie.Internal

Methods

traverse :: Applicative f => (a -> f b) -> Trie a -> f (Trie b) #

sequenceA :: Applicative f => Trie (f a) -> f (Trie a) #

mapM :: Monad m => (a -> m b) -> Trie a -> m (Trie b) #

sequence :: Monad m => Trie (m a) -> m (Trie a) #

Eq a => Eq (Trie a) 
Instance details

Defined in Data.Trie.Internal

Methods

(==) :: Trie a -> Trie a -> Bool #

(/=) :: Trie a -> Trie a -> Bool #

Show a => Show (Trie a) 
Instance details

Defined in Data.Trie.Internal

Methods

showsPrec :: Int -> Trie a -> ShowS #

show :: Trie a -> String #

showList :: [Trie a] -> ShowS #

Semigroup a => Semigroup (Trie a) 
Instance details

Defined in Data.Trie.Internal

Methods

(<>) :: Trie a -> Trie a -> Trie a #

sconcat :: NonEmpty (Trie a) -> Trie a #

stimes :: Integral b => b -> Trie a -> Trie a #

Monoid a => Monoid (Trie a) 
Instance details

Defined in Data.Trie.Internal

Methods

mempty :: Trie a #

mappend :: Trie a -> Trie a -> Trie a #

mconcat :: [Trie a] -> Trie a #

Binary a => Binary (Trie a) 
Instance details

Defined in Data.Trie.Internal

Methods

put :: Trie a -> Put #

get :: Get (Trie a) #

putList :: [Trie a] -> Put #

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 [(ByteString, RouteLeaf a)] m => Route -> m (Resource a) -> m () Source #

runRouter :: RoutingSpec m a -> Trie (RouteLeaf m) Source #

Turns the list of routes in a RoutingSpec into a Trie for efficient routing