Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module reexports Wheb modules. It should be the only thing you need to import to get started.
import Web.Wheb import Data.Text.Lazy (pack) main :: IO () main = do opts <- generateOptions $ addGET (pack ".") rootPat $ (text (pack "Hi!")) runWhebServer opts
- getApp :: Monad m => WhebT g s m g
- getWithApp :: Monad m => (g -> a) -> WhebT g s m a
- getHandlerState :: Monad m => WhebT g s m s
- putHandlerState :: Monad m => s -> WhebT g s m ()
- modifyHandlerState :: Monad m => (s -> s) -> WhebT g s m s
- modifyHandlerState' :: Monad m => (s -> s) -> WhebT g s m ()
- html :: Monad m => Text -> WhebHandlerT g s m
- text :: Monad m => Text -> WhebHandlerT g s m
- file :: Monad m => Text -> Text -> WhebHandlerT g s m
- builder :: Monad m => Text -> Builder -> WhebHandlerT g s m
- redirect :: Monad m => Text -> WhebHandlerT g s m
- setHeader :: Monad m => Text -> Text -> WhebT g s m ()
- setRawHeader :: Monad m => Header -> WhebT g s m ()
- getSetting :: Monad m => Text -> WhebT g s m (Maybe Text)
- getSetting' :: (Monad m, Typeable a) => Text -> WhebT g s m (Maybe a)
- getSetting'' :: (Monad m, Typeable a) => Text -> a -> WhebT g s m a
- getSettings :: Monad m => WhebT g s m CSettings
- getRouteParams :: Monad m => WhebT g s m RouteParamList
- getRouteParam :: (Typeable a, Monad m) => Text -> WhebT g s m a
- getRoute :: Monad m => Text -> RouteParamList -> WhebT g s m Text
- getRoute' :: Monad m => Text -> RouteParamList -> WhebT g s m (Either UrlBuildError Text)
- getRequest :: Monad m => WhebT g s m Request
- getRequestHeader :: Monad m => Text -> WhebT g s m (Maybe Text)
- getWithRequest :: Monad m => (Request -> a) -> WhebT g s m a
- getQueryParams :: Monad m => WhebT g s m Query
- getPOSTParam :: MonadIO m => Text -> WhebT g s m (Maybe Text)
- getPOSTParams :: MonadIO m => WhebT g s m [(Text, Text)]
- getRawPOST :: MonadIO m => WhebT g s m ([Param], [File ByteString])
- runWhebServer :: WhebOptions g s IO -> IO ()
- runWhebServerT :: (forall a. m a -> IO a) -> WhebOptions g s m -> IO ()
- runRawHandler :: WhebOptions g s IO -> WhebT g s IO a -> IO (Either WhebError a)
- runRawHandlerT :: WhebOptions g s m -> (m (Either WhebError a) -> IO (Either WhebError a)) -> Request -> WhebT g s m a -> IO (Either WhebError a)
- addGET :: Text -> UrlPat -> WhebHandlerT g s m -> InitM g s m ()
- addPOST :: Text -> UrlPat -> WhebHandlerT g s m -> InitM g s m ()
- addPUT :: Text -> UrlPat -> WhebHandlerT g s m -> InitM g s m ()
- addDELETE :: Text -> UrlPat -> WhebHandlerT g s m -> InitM g s m ()
- addRoute :: Route g s m -> InitM g s m ()
- addRoutes :: [Route g s m] -> InitM g s m ()
- catchAll :: WhebHandlerT g s m -> InitM g s m ()
- addWhebSocket :: UrlPat -> WhebSocket g s m -> InitM g s m ()
- addSite :: Text -> Site url (WhebHandlerT g s m) -> InitM g s m ()
- addWAIMiddleware :: Middleware -> InitM g s m ()
- addWhebMiddleware :: WhebMiddleware g s m -> InitM g s m ()
- addSetting :: Text -> Text -> InitM g s m ()
- addSetting' :: Typeable a => Text -> a -> InitM g s m ()
- addSettings :: CSettings -> InitM g s m ()
- readSettingsFile :: FilePath -> InitM g s m ()
- addCleanupHook :: IO () -> InitM g s m ()
- generateOptions :: MonadIO m => InitM g s m (g, s) -> IO (WhebOptions g s m)
- genMinOpts :: InitM () () IO () -> IO MinOpts
- compilePat :: UrlPat -> UrlParser
- rootPat :: UrlPat
- (</>) :: UrlPat -> UrlPat -> UrlPat
- grabInt :: Text -> UrlPat
- grabText :: Text -> UrlPat
- pT :: Text -> UrlPat
- pS :: String -> UrlPat
- spack :: Show a => a -> Text
- class Monad m => MonadIO m where
- module Web.Wheb.Types
Handlers
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
Dealing with responses
Creating a HandlerResponse
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
Setting a header
setRawHeader :: Monad m => Header -> WhebT g s m () Source
Set a Strict ByteString header for the response
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 (Either UrlBuildError Text) Source
Generate a route from a name and param list.
Request reading
getRequest :: Monad m => WhebT g s m Request Source
Access the request
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.
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
Initialize
Routes
Named routes convenience functions
Add raw routes
catchAll :: WhebHandlerT g s m -> InitM g s m () Source
Catch all requests regardless of method or path
Sockets
addWhebSocket :: UrlPat -> WhebSocket g s m -> InitM g s m () Source
Sites
Middlewares
addWAIMiddleware :: Middleware -> InitM g s m () Source
Add generic WAI middleware
addWhebMiddleware :: WhebMiddleware g s m -> InitM g s m () Source
Add Wheb specific middleware
Settings
addSetting :: Text -> Text -> InitM g s m () Source
Wrapped addSetting'
to help prevent monomorphism errors for simple settings.
addSetting' :: Typeable a => Text -> a -> InitM g s m () Source
Adds a setting value, replacing it if its key already exists.
addSettings :: CSettings -> InitM g s m () Source
readSettingsFile :: FilePath -> InitM g s m () Source
Cleanup
addCleanupHook :: IO () -> InitM g s m () Source
IO Actions to run after server has been stopped.
Running
generateOptions :: MonadIO m => InitM g s m (g, s) -> IO (WhebOptions g s m) Source
Generate WhebOptions
from InitM
in IO
genMinOpts :: InitM () () IO () -> IO MinOpts Source
Generate options for an application without a context or state
Routes
URL Patterns
URL building
(</>) :: UrlPat -> UrlPat -> UrlPat Source
Allows for easier building of URL patterns This should be the primary URL constructor.
(\"blog\" '</>' ('grabInt' \"pk\") '</>' \"edit\" '</>' ('grabText' \"verb\"))
Utilities
class Monad m => MonadIO m where
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
MonadIO IO | |
MonadIO m => MonadIO (ListT m) | |
MonadIO m => MonadIO (ResourceT m) | |
MonadIO m => MonadIO (MaybeT m) | |
MonadIO m => MonadIO (IdentityT m) | |
MonadIO m => MonadIO (ContT r m) | |
MonadIO m => MonadIO (ReaderT r m) | |
MonadIO m => MonadIO (StateT s m) | |
MonadIO m => MonadIO (StateT s m) | |
MonadIO m => MonadIO (ExceptT e m) | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
MonadIO m => MonadIO (RouteT url m) | |
MonadIO (InitM g s m) | |
MonadIO m => MonadIO (WhebT g s m) | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) |
Types
module Web.Wheb.Types