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

Safe HaskellNone
LanguageHaskell2010

Web.Respond.Response

Contents

Description

utilities and defaults for sending responses.

Synopsis

headers

getAcceptHeader :: MonadRespond m => m ByteString Source

get the value of the Accept header, falling back to "*/*" if it was not sent in the request

constructing responses

respondEmptyBody :: MonadRespond m => Status -> ResponseHeaders -> m ResponseReceived Source

responding with an empty body means not having to worry about the Accept header.

respondUsingBody :: MonadRespond m => Status -> ResponseHeaders -> ResponseBody -> m ResponseReceived Source

respond by getting the information from a ResponseBody

respondWith :: (MonadRespond m, ToResponseBody a) => Status -> ResponseHeaders -> a -> m ResponseReceived Source

respond by using the ToResponseBody instance for the value and determining if it can be converted into an acceptable response body.

calls handleUnacceptableResponse if an acceptable content type cannot be produced..

respondStdHeaders :: (MonadRespond m, ToResponseBody a) => Status -> a -> m ResponseReceived Source

respond with no additional headers

respondOk :: (MonadRespond m, ToResponseBody a) => a -> m ResponseReceived Source

respond with 200 Ok

respondReportError :: (MonadRespond m, ReportableError e) => Status -> ResponseHeaders -> e -> m ResponseReceived Source

respond using a ReportableError to generate the response body.

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

respond that something was not found

use the RequestErrorHandlers

handleUnsupportedMethod :: MonadRespond m => [StdMethod] -> Method -> m ResponseReceived Source

an action that gets the currently installed unsupported method handler and applies it to the arguments

handleUnmatchedPath :: MonadRespond m => m ResponseReceived Source

an action that gets the installed unmatched path handler and uses it

handleUnacceptableResponse :: MonadRespond m => m ResponseReceived Source

get and use handler for unacceptable response types

useHandlerForReport Source

Arguments

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

a handler-getter that gets a handler that takes an error report

-> e

the error

-> m ResponseReceived 

generic handler-getter for things that use ErrorReports

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

an action that gets the installed body parse failure handler and applies it

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

get and use installed auth failed handler

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

get and use access denied handler

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

get and use handler for caught exceptions.

getHandler :: MonadRespond m => (FailureHandlers -> a) -> m a Source

get a specific handler.

getHandler = (<$> getHandlers)

other response utilities.

maybeNotFound :: (ReportableError e, MonadRespond m) => e -> (a -> m ResponseReceived) -> Maybe a -> m ResponseReceived Source

a way to use Maybe values to produce 404s

catchRespond :: (MonadCatch m, MonadRespond m, ReportableError r, Exception e) => (e -> r) -> m ResponseReceived -> m ResponseReceived Source

catch Exceptions using MonadCatch, and use handleCaughtException to respond with an error report.