restful-snap-0.1.1.1

Safe HaskellNone

Snap.Restful

Synopsis

Documentation

data CRUD Source

Enumeration of all the different types of CRUD routes.

Constructors

RIndex

An item index

RShow

A single item

RNew

The form for creating a new item

REdit

The form for editing an item

RCreate

Create a new item

RUpdate

Update an item

RDestroy

Delete an item

Instances

data Resource Source

Encapsulates the data necessary to define a resource.

Constructors

Resource 

Fields

rName :: Text

A name for this resource

rRoot :: Text

URL root for this resource

rResourceEndpoints :: [Text]

Resource level routing end points

rItemEndpoints :: [Text]

Item/instance level routing end points

Instances

newtype DBId Source

Constructors

DBId 

Fields

unDBId :: Word64
 

iPrimShow :: (Monad m, Show a) => a -> m [Node]Source

addResourceSource

Arguments

:: 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

-> 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.

addResourceRelativeSource

Arguments

:: 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

-> 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.

unitLens :: Lens' b ()Source

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.

indexPath :: Resource -> TextSource

Generates the path for the resource index.

createPath :: Resource -> TextSource

Generates the path for creating a resource.

showPath :: Resource -> DBId -> TextSource

Generates the path for showing a single resource item.

newPath :: Resource -> TextSource

Generates the path for a form to a new resource.

editPath :: Resource -> DBId -> TextSource

Generates the path for a form to a new 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.

itemActionPath :: Resource -> Text -> DBId -> TextSource

Generates a path for an item action.

templatePath :: Resource -> CRUD -> ByteStringSource

Return heist template location for given crud action

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.

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.

setFormAction :: MonadSnap m => Text -> m a -> m aSource

Sets the RESTFormAction param.

getFormAction :: MonadSnap m => HeistT n m [Node]Source

Gets the RESTFormAction param.

simpleDateFormlet :: Monad m => Maybe Day -> Form Text m DaySource

A simple formlet for dates that