Safe Haskell | Safe-Infered |
---|
This module defines the RestController
class
- class Monad m => RestController m a where
- restIndex :: a -> Action t m ()
- restShow :: a -> ByteString -> Action t m ()
- restNew :: a -> Action t m ()
- restCreate :: a -> Action t m ()
- restEdit :: a -> ByteString -> Action t m ()
- restUpdate :: a -> ByteString -> Action t m ()
- restDestroy :: a -> ByteString -> Action t m ()
- routeRestController :: RestController m a => String -> a -> HttpRoute m t
Documentation
class Monad m => RestController m a whereSource
The class RestController
allows a set of actions to be routed using
RESTful HTTP verbs.
restIndex :: a -> Action t m ()Source
GET /
restShow :: a -> ByteString -> Action t m ()Source
GET /:id
id
is passed in as the second parameter.
restNew :: a -> Action t m ()Source
GET /new
restCreate :: a -> Action t m ()Source
POST /
restEdit :: a -> ByteString -> Action t m ()Source
GET /:id/edit
id
is passed in as the second parameter.
restUpdate :: a -> ByteString -> Action t m ()Source
PUT /:id
id
is passed in as the second parameter.
Since PUT
is not supported by many browsers, this action also responds to
requests containing the HTTP header X-HTTP-Method-Override: PUT
regardless of the actual HTTP method (GET
or POST
)
restDestroy :: a -> ByteString -> Action t m ()Source
DELETE /:id
id
is passed in as the second parameter.
Since DELETE
is not supported by many browsers, this action also responds to
requests containing the HTTP header X-HTTP-Method-Override: DELETE
regardless of the actual HTTP method (GET
or POST
)
routeRestController :: RestController m a => String -> a -> HttpRoute m tSource
Routes URLs under the given String
to actions in a RestController
. For
example
routeRestController posts myRestController
will map the follwoing URLs:
- GET /posts => myRestController#restIndex
- POST /posts => myRestController#restCreate
- GET /posts/:id => myRestController#restShow
- GET /posts/:id/edit => myRestController#restEdit
- GET /posts/:id/new => myRestController#restNew
- DELETE /posts/:id => myRestController#restDestroy
- PUT /posts/:id => myRestController#restUpdate