growler-0.6.0: A revised version of the scotty library that attempts to be simpler and more performant.

Safe HaskellNone
LanguageHaskell2010

Web.Growler.Handler

Synopsis

Documentation

abort :: Monad m => ResponseState -> HandlerT m () Source

End the handler early with an arbitrary ResponseState.

status :: Monad m => Status -> HandlerT m () Source

Set the response status code.

addHeader :: Monad m => CI ByteString -> ByteString -> HandlerT m () Source

Add a header to the response. Header names are case-insensitive.

setHeader :: Monad m => CI ByteString -> ByteString -> HandlerT m () Source

Set a response header. Overrides duplicate headers of the same name.

body :: Monad m => BodySource -> HandlerT m () Source

Set an arbitrary body source for the response.

file Source

Arguments

:: Monad m 
=> FilePath

The file to send

-> Maybe FilePart

If Nothing, then send the whole file, otherwise, the part specified

-> HandlerT m () 

Send a file as the response body.

builder :: Monad m => Builder -> HandlerT m () Source

Set the response body to a ByteString Builder. Sets no headers.

bytestring :: Monad m => ByteString -> HandlerT m () Source

Set the response body to a lazy ByteString. Sets no headers.

stream :: Monad m => StreamingBody -> HandlerT m () Source

Send a streaming response body. Sets no headers.

raw Source

Arguments

:: MonadIO m 
=> (IO ByteString -> (ByteString -> IO ()) -> IO ()) 
-> Response

Backup response when the WAI provider doesn't support upgrading (e.g. CGI)

-> HandlerT m () 

Send raw output as the response body. Useful for e.g. websockets. See WAI's responseRaw for more details.

json :: Monad m => ToJSON a => a -> HandlerT m () Source

Send a value as JSON as the response body. Also sets the content type to application/json.

formData :: MonadIO m => BackEnd y -> HandlerT m ([(ByteString, ByteString)], [File y]) Source

Parse out the form parameters and the uploaded files. Consumes the request body.

headers :: Monad m => HandlerT m RequestHeaders Source

Get all the request headers.

jsonData :: (FromJSON a, MonadIO m) => HandlerT m (Either JsonInputError a) Source

Consume the request body as a JSON value. Returns a JsonInputError on failure.

params :: Monad m => HandlerT m [Param] Source

Get all matched params.

redirect Source

Arguments

:: Monad m 
=> Text

URL to redirect to.

-> HandlerT m () 

Terminate the current handler and send a 302 Found redirect to the provided URL. Other headers that have already been set will also be returned in the request.

request :: Monad m => HandlerT m Request Source

Get the underlying WAI Request

text :: Monad m => Text -> HandlerT m () Source

Return plain text as the response body. Sets the Content-Type header to "text/plain; charset=utf-8".

html :: Monad m => Text -> HandlerT m () Source

Return HTML as the response body. Sets the Content-Type header to "text/html; charset=utf-8". If you're using something like blaze-html or lucid, you'll probably get better performance by rolling your own function that sets the response body to a Builder.

routePattern :: Monad m => HandlerT m (Maybe Text) Source

Get the pattern that was matched in the router, e.g. "foo:bar"

liftAround :: Monad m => (forall a. m a -> m a) -> HandlerT m a -> HandlerT m a Source