web-inv-route 0.1.1 → 0.1.2
raw patch · 5 files changed
+72/−5 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Web.Route.Invertible: fromMethod :: IsMethod m => Method -> Maybe m
+ Web.Route.Invertible.Internal: fromMethod :: IsMethod m => Method -> Maybe m
+ Web.Route.Invertible.Wai: routeWaiError :: (Status -> ResponseHeaders -> Request -> a) -> RouteMap (Request -> a) -> Request -> a
- Web.Route.Invertible.Common: class (RouteString s, Typeable a) => Parameter s a where parseParameter = readMaybe . toString renderParameter = fromString . show
+ Web.Route.Invertible.Common: class (RouteString s, Typeable a) => Parameter s a
Files
- LICENSE +26/−0
- Web/Route/Invertible/Method.hs +35/−0
- Web/Route/Invertible/Wai.hs +6/−1
- test/Main.hs +1/−1
- web-inv-route.cabal +4/−3
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) 2016-2018, Dylan Simon+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice,+ this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+3. Neither the name of the <ORGANIZATION> nor the names of its+ contributors may be used to endorse or promote products derived from+ this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
Web/Route/Invertible/Method.hs view
@@ -49,9 +49,11 @@ -- |Any types that represent an HTTP method. class IsMethod m where toMethod :: m -> Method+ fromMethod :: Method -> Maybe m instance IsMethod Method where toMethod = id+ fromMethod = Just instance IsMethod H.StdMethod where toMethod H.GET = GET@@ -63,9 +65,21 @@ toMethod H.CONNECT = CONNECT toMethod H.OPTIONS = OPTIONS toMethod H.PATCH = PATCH+ fromMethod GET = Just H.GET+ fromMethod POST = Just H.POST+ fromMethod HEAD = Just H.HEAD+ fromMethod PUT = Just H.PUT+ fromMethod DELETE = Just H.DELETE+ fromMethod TRACE = Just H.TRACE+ fromMethod CONNECT = Just H.CONNECT+ fromMethod OPTIONS = Just H.OPTIONS+ fromMethod PATCH = Just H.PATCH+ fromMethod _ = Nothing instance IsMethod (Either ByteString H.StdMethod) where toMethod = either ExtensionMethod toMethod+ fromMethod (ExtensionMethod e) = Just $ Left e+ fromMethod m = Right <$> fromMethod m instance IsMethod ByteString where toMethod "OPTIONS" = OPTIONS@@ -78,6 +92,7 @@ toMethod "CONNECT" = CONNECT toMethod "PATCH" = PATCH toMethod m = ExtensionMethod m+ fromMethod = Just . renderParameter #ifdef VERSION_snap_core instance IsMethod Snap.Method where@@ -91,6 +106,16 @@ toMethod Snap.CONNECT = CONNECT toMethod Snap.PATCH = PATCH toMethod (Snap.Method m) = ExtensionMethod m+ fromMethod GET = Just Snap.GET+ fromMethod HEAD = Just Snap.HEAD+ fromMethod POST = Just Snap.POST+ fromMethod PUT = Just Snap.PUT+ fromMethod DELETE = Just Snap.DELETE+ fromMethod TRACE = Just Snap.TRACE+ fromMethod OPTIONS = Just Snap.OPTIONS+ fromMethod CONNECT = Just Snap.CONNECT+ fromMethod PATCH = Just Snap.PATCH+ fromMethod (ExtensionMethod m) = Just $ Snap.Method m #endif #ifdef VERSION_happstack_server@@ -105,4 +130,14 @@ toMethod HS.CONNECT = CONNECT toMethod HS.PATCH = PATCH toMethod (HS.EXTENSION m) = ExtensionMethod m+ fromMethod GET = Just HS.GET+ fromMethod HEAD = Just HS.HEAD+ fromMethod POST = Just HS.POST+ fromMethod PUT = Just HS.PUT+ fromMethod DELETE = Just HS.DELETE+ fromMethod TRACE = Just HS.TRACE+ fromMethod OPTIONS = Just HS.OPTIONS+ fromMethod CONNECT = Just HS.CONNECT+ fromMethod PATCH = Just HS.PATCH+ fromMethod (ExtensionMethod m) = Just $ HS.EXTENSION m #endif
Web/Route/Invertible/Wai.hs view
@@ -3,6 +3,7 @@ ( module Web.Route.Invertible.Common , waiRequest , routeWai+ , routeWaiError , routeWaiApplicationError , routeWaiApplication ) where@@ -33,8 +34,12 @@ routeWai = routeRequest . waiRequest -- |Combine a set of applications in a routing map into a single application, calling a custom error handler in case of routing error.+routeWaiError :: (Status -> ResponseHeaders -> Wai.Request -> a) -> RouteMap (Wai.Request -> a) -> Wai.Request -> a+routeWaiError e m q = either (\(s, h) -> e s h q) (\a -> a q) $ routeWai q m++-- |Equivalent to 'routeWaiError'. routeWaiApplicationError :: (Status -> ResponseHeaders -> Wai.Application) -> RouteMap Wai.Application -> Wai.Application-routeWaiApplicationError e m q = either (\(s, h) -> e s h q) (\a -> a q) $ routeWai q m+routeWaiApplicationError = routeWaiError -- |Combine a set of applications in a routing map into a single application, returning an empty error response in case of routing error. routeWaiApplication :: RouteMap Wai.Application -> Wai.Application
test/Main.hs view
@@ -30,7 +30,7 @@ "post thing=" ++ i anyThingSub :: RouteAction (Int, [Int]) String-anyThingSub = routePath ("thing" *< parameter >* "sub" >*< manyI parameter) `RouteAction` \(i, l) ->+anyThingSub = routePath (("thing" *< parameter >* "sub") >*< manyI parameter) `RouteAction` \(i, l) -> "thing" ++ show i ++ " sub" ++ concatMap ((' ' :) . show) l ignoredThing :: RouteAction Int String
web-inv-route.cabal view
@@ -1,6 +1,6 @@ name: web-inv-route-version: 0.1.1-synopsis: Composable, reversible, efficient web routing based on invertible invariants and bijections+version: 0.1.2+synopsis: Composable, reversible, efficient web routing using invertible invariants and bijections description: Utilities to route HTTP requests, mainly focused on path components. Routes are specified using bijections and invariant functors, allowing run-time composition (routes can be distributed across modules), reverse and forward routing derived from the same specification, and O(log n) lookups. .@@ -17,9 +17,10 @@ Most users will just want to import a framework-specific module like "Web.Route.Invertible.Wai" (or the generic "Web.Route.Invertible"), each of which re-exports "Web.Route.Invertible.Common". See test/Main.hs for some examples. license: BSD3+license-file: LICENSE author: Dylan Simon maintainer: dylan@dylex.net-copyright: 2016+copyright: 2016-2018 category: Web build-type: Simple cabal-version: >=1.20