snaplet-rest-0.1.0: REST resources for the Snap web framework

Safe HaskellNone

Snap.Snaplet.Rest.Config

Contents

Synopsis

Configuration

data ResourceConfig m Source

Configuration data.

Constructors

ResourceConfig 

Fields

readLimit :: Maybe Int

The maximum number of members to retrieve from a collection in a single request.

maxRequestBodySize :: Int64

Maximum size of request bodies allowed when receiving resources.

onHeaderFailure :: m ()

Action to run if the request header parsing fails.

onPathFailure :: m ()

Action to run if the resource path parsing fails.

onQueryFailure :: m ()

Action to run if the URL query string parsing fails.

onLookupFailure :: m ()

Action to run if the requested resource cannot be found.

onMethodFailure :: m ()

Action to run an invalid method is requested on a resource.

onAcceptFailure :: m ()

Action to run if the response media type is not supported.

onContentTypeFailure :: m ()

Action to run if the request media type is not supported.

onContentParseFailure :: m ()

Action to run if the request body parse fails.

defaultConfig :: MonadSnap m => Int64 -> ResourceConfig mSource

The default configuration settings. Requires a value for the maximum size of a request body.

 defaultConfig mrbs = ResourceConfig
     { readLimit = Nothing
     , maxRequestBodySize = mrbs
     , on*Failure = write "reason"
     }

Snaplet type class

class HasResourceConfig b whereSource

The type class for an implementing Snaplet.

Methods

resourceLens :: SnapletLens (Snaplet b) (ResourceConfig (Handler b b))Source

Retrieve the configuration from the Snaplet monad.

type Resources b = ResourceConfig (Handler b b)Source

Convenience alias of ResourceConfig.

resourceInit :: ResourceConfig (Handler b b) -> SnapletInit b (Resources b)Source

Initialize the resource snaplet with the given configuration.

resourceInitDefault :: Int64 -> SnapletInit b (Resources b)Source

Initialize the resource snaplet with the default configuration.

Local utility

getResourceConfig :: HasResourceConfig b => Handler b v (ResourceConfig (Handler b b))Source

Returns the resource configuration.