respond-1.0.0: process and route HTTP requests and generate responses on top of WAI

Safe HaskellNone
LanguageHaskell2010

Web.Respond.Monad

Contents

Description

you build your api using this stuff.

Synopsis

the monad interface

class (Functor m, MonadIO m) => MonadRespond m where Source

this class is the api for building your handler.

Methods

respond :: Response -> m ResponseReceived Source

perform the WAI application respond action (after converting the value to a response)

getRequest :: m Request Source

get out the request.

getHandlers :: m FailureHandlers Source

withHandlers :: (FailureHandlers -> FailureHandlers) -> m a -> m a Source

run an inner action that will see an updates set of error handlers. this is useful when you know that inner actions will need to do resource cleanup or something.

getPath :: m PathConsumer Source

get the path as it's been consumed so far.

withPath :: (PathConsumer -> PathConsumer) -> m a -> m a Source

run the inner action with an updated path state.

an implementation

data RespondT m a Source

RespondT is a monad transformer that provides an implementation of MonadRespond. you build your application using this.

runRespondT :: RespondT m a -> FailureHandlers -> Request -> Responder -> m a Source

run the RespondT action with failure handlers and request information.

mapRespondT :: (m a -> n b) -> RespondT m a -> RespondT n b Source

handling errors

data FailureHandlers Source

record containing responders that request matching tools can use when failures occur.

Constructors

FailureHandlers 

Fields

_unsupportedMethod :: MonadRespond m => [StdMethod] -> Method -> m ResponseReceived

what to do if the request method is not supported

_unmatchedPath :: MonadRespond m => m ResponseReceived

what to do if the request path has no matches

_bodyParseFailed :: (MonadRespond m, ReportableError e) => e -> m ResponseReceived

what to do if the body failed to parse

_authFailed :: (MonadRespond m, ReportableError e) => e -> m ResponseReceived

what to do when authentication fails

_accessDenied :: (MonadRespond m, ReportableError e) => e -> m ResponseReceived

what to do when authorization fails

_caughtException :: (MonadRespond m, ReportableError e) => e -> m ResponseReceived

what to do when an exception has been caught

_unacceptableResponse :: MonadRespond m => m ResponseReceived

what to do when no media type is acceptable

Getters for each handler