Wheb-0.2.0.0: The frictionless WAI Framework

Safe HaskellNone
LanguageHaskell2010

Web.Wheb.WhebT

Contents

Synopsis

ReaderT and StateT Functionality

ReaderT

getApp :: Monad m => WhebT g s m g Source

Get the g in WhebT g s m g. This is a read-only state so only thread-safe resources such as DB connections should go in here.

getWithApp :: Monad m => (g -> a) -> WhebT g s m a Source

StateT

getHandlerState :: Monad m => WhebT g s m s Source

Get the s in WhebT g s m g. This is a read and writable state so you can get and put information in your state. Each request gets its own fresh state duplicated from our options startingState

putHandlerState :: Monad m => s -> WhebT g s m () Source

modifyHandlerState :: Monad m => (s -> s) -> WhebT g s m s Source

modifyHandlerState' :: Monad m => (s -> s) -> WhebT g s m () Source

Responses

setHeader :: Monad m => Text -> Text -> WhebT g s m () Source

Set a header for the response

setRawHeader :: Monad m => Header -> WhebT g s m () Source

Set a Strict ByteString header for the response

html :: Monad m => Text -> WhebHandlerT g s m Source

Return simple HTML from Text

text :: Monad m => Text -> WhebHandlerT g s m Source

Return simple Text

file :: Monad m => Text -> Text -> WhebHandlerT g s m Source

Give filepath and content type to serve a file from disk.

builder :: Monad m => Text -> Builder -> WhebHandlerT g s m Source

Give content type and Blaze Builder

redirect :: Monad m => Text -> WhebHandlerT g s m Source

Redirect to a given URL

Settings

getSetting :: Monad m => Text -> WhebT g s m (Maybe Text) Source

Help prevent monomorphism errors for simple settings.

getSetting' :: (Monad m, Typeable a) => Text -> WhebT g s m (Maybe a) Source

Open up underlying support for polymorphic global settings

getSetting'' :: (Monad m, Typeable a) => Text -> a -> WhebT g s m a Source

Get a setting or a default

getSettings :: Monad m => WhebT g s m CSettings Source

Get all settings.

Routes

getRouteParams :: Monad m => WhebT g s m RouteParamList Source

Get all route params.

getRouteParam :: (Typeable a, Monad m) => Text -> WhebT g s m a Source

Cast a route param into its type.

getRoute :: Monad m => Text -> RouteParamList -> WhebT g s m Text Source

Convert Either from getRoute' into an error in the Monad

getRoute' :: Monad m => Text -> RouteParamList -> WhebT g s m (Either UrlBuildError Text) Source

Generate a route from a name and param list.

getRawRoute :: Monad m => Text -> RouteParamList -> WhebT g s m (Maybe (Route g s m)) Source

Generate the raw route

Request reading

getRequest :: Monad m => WhebT g s m Request Source

Access the request

getRequestHeader :: Monad m => Text -> WhebT g s m (Maybe Text) Source

Get a request header

getWithRequest :: Monad m => (Request -> a) -> WhebT g s m a Source

getQueryParams :: Monad m => WhebT g s m Query Source

Get params from URL (e.g. from '/foo/?q=4')

getPOSTParam :: MonadIO m => Text -> WhebT g s m (Maybe Text) Source

Maybe get one param if it exists.

getPOSTParams :: MonadIO m => WhebT g s m [(Text, Text)] Source

Get POST params as Text

getRawPOST :: MonadIO m => WhebT g s m ([Param], [File ByteString]) Source

Get the raw parsed POST data including files.

Running Wheb

runWhebServer :: WhebOptions g s IO -> IO () Source

Convenience wrapper for runWhebServerT function in IO

runWhebServerT :: (forall a. m a -> IO a) -> WhebOptions g s m -> IO () Source

Run a server with a function to run your inner Transformer to IO and generated options

runRawHandler :: WhebOptions g s IO -> WhebT g s IO a -> IO (Either WhebError a) Source

Convenience wrapper for runRawHandlerT function in IO

runRawHandlerT :: WhebOptions g s m -> (m (Either WhebError a) -> IO (Either WhebError a)) -> Request -> WhebT g s m a -> IO (Either WhebError a) Source

Running a Handler with a custom Transformer