Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type Router = Router' RoutingApplication
- data Router' a
- = WithRequest (Request -> Router)
- | StaticRouter (Map Text Router)
- | DynamicRouter (Text -> Router)
- | LeafRouter a
- | Choice Router Router
- tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router -> Router
- choice :: Router -> Router -> Router
- runRouter :: Router -> RoutingApplication
- worseHTTPCode :: Int -> Int -> Bool
Documentation
type Router = Router' RoutingApplication Source
Internal representation of a router.
WithRequest (Request -> Router) | current request is passed to the router |
StaticRouter (Map Text Router) | first path component used for lookup and removed afterwards |
DynamicRouter (Text -> Router) | first path component used for lookup and removed afterwards |
LeafRouter a | to be used for routes that match an empty path |
Choice Router Router | left-biased choice between two routers |
tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router -> Router Source
Apply a transformation to the response of a Router
.
choice :: Router -> Router -> Router Source
Smart constructor for the choice between routers. We currently optimize the following cases:
- Two static routers can be joined by joining their maps.
- Two dynamic routers can be joined by joining their codomains.
- Two
WithRequest
routers can be joined by passing them the same request and joining their codomains. - A
WithRequest
router can be joined with anything else by passing the same request to both but ignoring it in the component that does not need it.
runRouter :: Router -> RoutingApplication Source
Interpret a router as an application.
worseHTTPCode :: Int -> Int -> Bool Source