iterio-server-0.2: Library for building servers with IterIO

Safe HaskellSafe-Infered

Data.IterIO.Http.Support.RestController

Description

This module defines the RestController class

Synopsis

Documentation

class Monad m => RestController m a whereSource

The class RestController allows a set of actions to be routed using RESTful HTTP verbs.

Methods

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