Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add mkRest to embed as snaplet

  • Loading branch information...
commit e0e67c61d39e666fd7133402649ff6a5d0cdda4c 1 parent 4ae7650
@ozataman authored
Showing with 23 additions and 1 deletion.
  1. +23 −1 src/Snap/Restful.hs
View
24 src/Snap/Restful.hs
@@ -17,8 +17,8 @@ module Snap.Restful
, iPrimShow
, cPrimShow
-
, initRest
+ , mkRest
, resourceRouter
, resourceRoutes
@@ -56,6 +56,7 @@ module Snap.Restful
import Blaze.ByteString.Builder
import qualified Blaze.ByteString.Builder.Char8 as Build
import Control.Applicative
+import Control.Lens
import Control.Monad
import Control.Monad.Trans
import Data.ByteString.Char8 (ByteString)
@@ -84,6 +85,11 @@ import qualified Text.XmlHtml as X
------------------------------------------------------------------------------
+
+unitLens :: Lens' b ()
+unitLens = lens (const ()) (\a () -> a)
+
+
------------------------------------------------------------------------------
-- | Adds a prefix to the tag names for a list of splices. If the existing
-- tag name is empty, then the new tag name is just the prefix. Otherwise the
@@ -134,10 +140,26 @@ data Resource = Resource {
-- ^ Item/instance level routing end points
}
+
instance Default Resource where
def = Resource "items" "/items" [] []
+
+mkRest :: HasHeist b
+ => Resource
+ -> [(CRUD, Handler b () ())]
+ -> [(Text, Handler b () ())]
+ -> [(Text, Handler b () ())]
+ -> Snaplet (Heist b)
+ -> SnapletInit b ()
+mkRest res rHandlers rResourceActions rItemActions h =
+ makeSnaplet (T.concat [rName res, "-resource"])
+ (T.concat ["RESTful resource for ", rName res])
+ Nothing $
+ initRest res rHandlers rResourceActions rItemActions h
+
+
------------------------------------------------------------------------------
-- | One-stop convenience function to enable RESTful resources in your
-- application. Call this function from your initializer passing it all of
Please sign in to comment.
Something went wrong with that request. Please try again.