wai-middleware-route 0.1.0.2 → 0.2.0
raw patch · 2 files changed
+25/−24 lines, 2 filesdep ~waiPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: wai
API changes (from Hackage documentation)
- Network.Wai.Middleware.Route: (&~~) :: Method -> ByteString -> Rule
- Network.Wai.Middleware.Route: type Route = (Rule, Application)
- Network.Wai.Middleware.Route: type Rule = Request -> Bool
+ Network.Wai.Middleware.Route: rule :: Method -> ByteString -> Request -> Bool
- Network.Wai.Middleware.Route: dispatch :: [Route] -> Application -> Application
+ Network.Wai.Middleware.Route: dispatch :: [(Request -> Bool, Application)] -> Application -> Application
Files
src/Network/Wai/Middleware/Route.hs view
@@ -6,22 +6,21 @@ gives some sugar to life. -} -module Network.Wai.Middleware.Route where +module Network.Wai.Middleware.Route ( + -- * Dispatching + dispatch, + -- * Creating rules + rule +) where -import Data.List +import Data.List (find) import Data.ByteString (ByteString) import Text.Regex.Posix ((=~)) -import Control.Applicative +import Control.Applicative ((<$>), (<*>)) import Network.HTTP.Types (Method) -import Network.Wai - --- | Routing rule -type Rule = Request -> Bool - --- | Route for dispatch -type Route = (Rule, Application) +import Network.Wai (Request, Application, rawPathInfo, requestMethod) -{- | Dispatch. Seek for first route where the 'Rule' gives a positive result. +{- | Dispatch. Seek for first route where the \"rule\" gives a positive result. Uses 'find' instead 'filter' in @vhost@ > dispatch [ @@ -30,10 +29,11 @@ > ] defaultApp -} dispatch :: - [Route] -- ^ List of routes + [(Request -> Bool, Application)] + -- ^ List of routes -> Application -- ^ Default 'Application' -> Application -- ^ Returns founded 'Application'. If not found - returns - -- default. + -- default. dispatch routes def req = case find (\(b, _) -> b req) routes of Nothing -> def req @@ -42,15 +42,16 @@ {- | Syntax shugar for most frequently case: HTTP Method and Request path regex pattern. -> ("GET" &~~ "^/issues", app) +> ("*" `rule` "^/issues/any", app) +> (methodGet `rule` "^/issues", anotherApp) -} -(&~~) :: - Method -- ^ HTTP Method +rule :: + Method -- ^ HTTP Method. Use @\"*\"@ for any method -> ByteString -- ^ Request path pattern. - -> Rule -- ^ Routing rule -infixl 1 &~~ -method &~~ pattern = onPath method $ (=~ pattern) . rawPathInfo + -> Request -- ^ Request + -> Bool -- ^ Routing rule +rule method pattern = onPath method $ (=~ pattern) . rawPathInfo where - onPath :: Method -> Rule -> Rule + onPath :: Method -> (Request -> Bool) -> Request -> Bool onPath "*" p = p onPath m p = (&&) <$> (==m) . requestMethod <*> p
wai-middleware-route.cabal view
@@ -1,13 +1,13 @@ name: wai-middleware-route -version: 0.1.0.2 +version: 0.2.0 cabal-version: >= 1.8 build-type: Simple -synopsis: Wai dispatch middleware +synopsis: Wai routing middleware stability: Experimental author: Alexander Dorofeev category: Web license: BSD3 -description: Request dispatching Middleware for Wai. +description: \"Just enough\" request dispatching Middleware for Wai. maintainer: aka.spin@gmail.com license-file: LICENSE homepage: https://github.com/akaspin/wai-middleware-route @@ -20,7 +20,7 @@ hs-source-dirs: src build-depends: base >= 4 && < 5, - wai >= 0.4 && < 0.5, + wai >= 1.0, bytestring >= 0.9 && < 0.10, regex-posix >= 0.94.4, http-types >= 0.6 && < 0.7