Safe Haskell | None |
---|---|

Language | Haskell2010 |

## Synopsis

- data Route
- data RoutingSpec m a
- data RouteLeaf m
- data Trie a
- root :: Route
- var :: Text -> Route
- star :: Route
- (</>) :: Route -> Route -> Route
- (#>) :: MonadWriter [(ByteString, RouteLeaf a)] m => Route -> Resource a -> m ()
- (#>=) :: MonadWriter [(ByteString, RouteLeaf a)] m => Route -> m (Resource a) -> m ()
- runRouter :: RoutingSpec m a -> Trie (RouteLeaf m)

# Documentation

`Route`

s 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 `Route`

s) to `Resource`

s. `RoutingSpec`

s 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

## Instances

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

Defined in Airship.Internal.Route 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 # |

A map from `ByteString`

s 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 | |

Functor Trie | |

Applicative Trie | |

Foldable Trie | |

Defined in Data.Trie.Internal 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 # elem :: Eq a => a -> Trie a -> Bool # maximum :: Ord a => Trie a -> a # | |

Traversable Trie | |

Eq a => Eq (Trie a) | |

Show a => Show (Trie a) | |

Semigroup a => Semigroup (Trie a) | |

Monoid a => Monoid (Trie a) | |

Binary a => Binary (Trie a) | |

Represents the root resource (`/`

). This should usually be the first path declared in a `RoutingSpec`

.

Captures a wildcard route. For example,

` "emcees" ``</>`

star

will match `/emcees`

, `/emcees/biggie`

, `/emcees/earl/vince`

, and so on and so forth.

(#>) :: MonadWriter [(ByteString, RouteLeaf a)] m => Route -> Resource a -> m () Source #

(#>=) :: 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