Safe Haskell | None |
---|
- addResource :: HasHeist b => Resource -> [(CRUD, Handler b v ())] -> [(Text, Handler b v ())] -> [(Text, Handler b v ())] -> Snaplet (Heist b) -> Initializer b v ()
- addResourceRelative :: HasHeist b => Resource -> [(CRUD, Handler b v ())] -> [(Text, Handler b v ())] -> [(Text, Handler b v ())] -> Snaplet (Heist b) -> Initializer b v ()
- initRest :: HasHeist b => Resource -> [(CRUD, Handler b () ())] -> [(Text, Handler b () ())] -> [(Text, Handler b () ())] -> Snaplet (Heist b) -> SnapletInit b ()
- resourceSplices :: Monad m => Resource -> [(Text, HeistT n m Template)]
- itemSplices :: Monad m => Resource -> DBId -> [(Text, Splice m)]
- resourceCSplices :: MonadSnap m => Resource -> [(Text, Splice m)]
- itemCSplices :: Resource -> [(Text, DBId -> Text)]
- unitLens :: Lens' b ()
- resourceRouter :: MonadSnap m => Resource -> [(CRUD, m a)] -> [(Text, m a)] -> [(Text, m a)] -> m a
- resourceRoutes :: MonadSnap m => Resource -> [(CRUD, m a)] -> [(Text, m a)] -> [(Text, m a)] -> [(ByteString, m a)]
- data CRUD
- data Resource = Resource {
- rName :: Text
- rRoot :: Text
- rResourceEndpoints :: [Text]
- rItemEndpoints :: [Text]
- newtype DBId = DBId {}
- class HasFormlet a where
- class PrimSplice a where
- iPrimSplice :: Monad m => a -> m [Node]
- cPrimSplice :: a -> Builder
- iPrimText :: Monad m => Text -> m [Node]
- iPrimShow :: (Monad m, Show a) => a -> m [Node]
- cPrimShow :: Show a => a -> Builder
- rootPath :: Resource -> Text
- indexPath :: Resource -> Text
- createPath :: Resource -> Text
- showPath :: Resource -> DBId -> Text
- newPath :: Resource -> Text
- editPath :: Resource -> DBId -> Text
- updatePath :: Resource -> DBId -> Text
- destroyPath :: Resource -> DBId -> Text
- itemActionPath :: Resource -> Text -> DBId -> Text
- templatePath :: Resource -> CRUD -> ByteString
- redirToItem :: MonadSnap m => Resource -> DBId -> m a
- prefixSplices :: Text -> [(Text, a)] -> [(Text, a)]
- relativeRedirect :: MonadSnap m => ByteString -> m b
- setFormAction :: MonadSnap m => Text -> m a -> m a
- getFormAction :: MonadSnap m => HeistT n m [Node]
- simpleDateFormlet :: Monad m => Maybe Day -> Form Text m Day
Core API
:: HasHeist b | |
=> Resource | Resource definition |
-> [(CRUD, Handler b v ())] | Standard CRUD handlers |
-> [(Text, Handler b v ())] | Additional resource level handlers |
-> [(Text, Handler b v ())] | Additional instance/item level handlers |
-> Snaplet (Heist b) | The Heist snaplet initialized in your app's |
-> Initializer b v () |
One-stop convenience function to enable RESTful resources in your application. Call this function from your initializer passing it all of your resources and it will add the routes and splices for you.
:: HasHeist b | |
=> Resource | Resource definition |
-> [(CRUD, Handler b v ())] | Standard CRUD handlers |
-> [(Text, Handler b v ())] | Additional resource level handlers |
-> [(Text, Handler b v ())] | Additional instance/item level handlers |
-> Snaplet (Heist b) | The Heist snaplet initialized in your app's
|
-> Initializer b v () |
Just like addResource
, but makes the handlers relative to the current
snaplet's root. Use this function if you're writing a snaplet.
initRest :: HasHeist b => Resource -> [(CRUD, Handler b () ())] -> [(Text, Handler b () ())] -> [(Text, Handler b () ())] -> Snaplet (Heist b) -> SnapletInit b ()Source
An initializer for encapsulating RESTful resources as a standalone snaplet.
Splice functions
resourceSplices :: Monad m => Resource -> [(Text, HeistT n m Template)]Source
Paths at the resource/collection level
itemSplices :: Monad m => Resource -> DBId -> [(Text, Splice m)]Source
Generates path splices for a resource item. These splices let you put resource links in your templates in DRY manner.
resourceCSplices :: MonadSnap m => Resource -> [(Text, Splice m)]Source
Returns compiled splices for a resource.
itemCSplices :: Resource -> [(Text, DBId -> Text)]Source
Generates compiled path splices for a resource item. These splices let you put resource links in your templates in DRY manner.
Since initRest
returns unit, we provide a generic unit lens here for
use with nestSnaplet in case you don't want to add a unit field to your
application state type.
resourceRouter :: MonadSnap m => Resource -> [(CRUD, m a)] -> [(Text, m a)] -> [(Text, m a)] -> m aSource
Generate a route handler for the routes returned by resourceRoutes. This function does add the rRoot prefix.
resourceRoutes :: MonadSnap m => Resource -> [(CRUD, m a)] -> [(Text, m a)] -> [(Text, m a)] -> [(ByteString, m a)]Source
See addResource
for an explanation of the arguments to this
function. The routes returned ARE prefixed with rRoot from
Resource.
Types
Enumeration of all the different types of CRUD routes.
Encapsulates the data necessary to define a resource.
Resource | |
|
Generating forms and splices
class HasFormlet a whereSource
Type class for automatic formlet generation.
class PrimSplice a whereSource
Type class for automatic splice generation.
iPrimSplice :: Monad m => a -> m [Node]Source
cPrimSplice :: a -> BuilderSource
Functions for generating paths
createPath :: Resource -> TextSource
Generates the path for creating a resource.
updatePath :: Resource -> DBId -> TextSource
Generates the path for updating a single resource item.
destroyPath :: Resource -> DBId -> TextSource
Generates the path for deleting a resource item.
templatePath :: Resource -> CRUD -> ByteStringSource
Return heist template location for given crud action
Misc helpers
redirToItem :: MonadSnap m => Resource -> DBId -> m aSource
Redirect to given item's default show page
prefixSplices :: Text -> [(Text, a)] -> [(Text, a)]Source
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 new tag name is the prefix followed by an underscore followed by the existing name.
relativeRedirect :: MonadSnap m => ByteString -> m bSource
setFormAction :: MonadSnap m => Text -> m a -> m aSource
Sets the RESTFormAction
param.
getFormAction :: MonadSnap m => HeistT n m [Node]Source
Gets the RESTFormAction
param.