-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A minimalist web framework for the WAI server interface -- -- Simple is "framework-less" web framework for Haskell web applications -- based on the WAI server interface (e.g. for use with the warp server). -- Simple does not enforce a particular structure or paradigm for web -- applications. Rather, Simple contains tools to help you create your -- own patterns (or re-create existing ones). Simple is minimalist, -- providing a lightweight base - the most basic Simple app is little -- more than a WAI Application with some routing logic. Everything -- else (e.g. authentication, controllers, persistence, caching etc') is -- provided in composable units, so you can include only the ones you -- need in your app, and easily replace with your own components. -- -- To get started, create an app skeleton with the smpl utility: -- --
--   $ cabal install simple
--   $ smpl create my_app_name
--   $ cd my_app_name
--   $ smpl
--   
-- -- See Web.Simple for a more detailed introduction. @package simple @version 0.5.0 -- | Provides a general caching interface along with a simple in-memory -- (process only) and file based cache implementations. module Web.Simple.Cache -- | A class that captures a simple key-value caching interface. The keys -- are simply 'String'\'s and values are simply 'ByteString'\'s. class Cache c put :: (Cache c, MonadIO m) => c -> String -> ByteString -> m ByteString fetch :: (Cache c, MonadIO m) => c -> String -> m (Maybe ByteString) invalidate :: (Cache c, MonadIO m) => c -> String -> m () fetchOr :: (Cache c, MonadIO m) => c -> String -> m ByteString -> m ByteString -- | A file based cache implementation. Files are stored in subdirectories -- of fsCacheBase. data FileSystemCache -- | Create a new FileSystemCache. newFileSystemCache :: FilePath -> FileSystemCache -- | An in-memory cache implementation. The current processes heap space is -- simply used as the cache. data InMemCache -- | Create a new InMemCache. newInMemCache :: MonadIO m => m InMemCache instance Cache InMemCache instance Cache FileSystemCache -- | This module defines some convenience functions for creating responses. module Web.Simple.Responses -- | Creates a 200 (OK) Response with the given content-type and -- resposne body ok :: ContentType -> ByteString -> Response -- | Creates a 200 (OK) Response with content-type "text/html" and -- the given resposne body okHtml :: ByteString -> Response -- | Creates a 200 (OK) Response with content-type -- "application/json" and the given resposne body okJson :: ByteString -> Response -- | Given a URL returns a 301 (Moved Permanently) Response -- redirecting to that URL. movedTo :: String -> Response -- | Given a URL returns a 303 (See Other) Response redirecting to -- that URL. redirectTo :: String -> Response -- | Returns a 400 (Bad Request) Response. badRequest :: Response -- | Returns a 401 (Authorization Required) Response requiring basic -- authentication in the given realm. requireBasicAuth :: String -> Response -- | Returns a 403 (Forbidden) Response. forbidden :: Response -- | Returns a 404 (Not Found) Response. notFound :: Response -- | Returns a 500 (Server Error) Response. serverError :: ByteString -> Response -- | Controller provides a convenient syntax for writting -- Application code as a Monadic action with access to an HTTP -- request as well as app specific data (e.g. a database connection pool, -- app configuration etc.) This module also defines some helper functions -- that leverage this feature. For example, redirectBack reads the -- underlying request to extract the referer and returns a redirect -- response: -- --
--   myController = do
--     ...
--     if badLogin then
--       redirectBack
--       else
--         ...
--   
module Web.Simple.Controller -- | The Controller Monad is both a Reader-like monad which, when run, -- computes either a Response or a result. Within the Controller -- Monad, the remainder of the computation can be short-circuited by -- responding with a Response. newtype Controller r a Controller :: ((r, Request) -> ResourceT IO (Either Response a)) -> Controller r a runController :: Controller r a -> r -> Request -> ResourceT IO (Either Response a) -- | Run a Controller in the IO monad runControllerIO :: Controller r a -> r -> Request -> IO (Either Response a) -- | Convert the controller into an Application controllerApp :: r -> Controller r a -> Application -- | Extract the application-specific state controllerState :: Controller r r -- | Modify the application state for the given computation localState :: (r -> r) -> Controller r a -> Controller r a -- | Extract the request request :: Controller r Request -- | Modify the request for the given computation localRequest :: (Request -> Request) -> Controller r a -> Controller r a -- | Provide a response -- --
--   respond r >>= f === respond r
--   
respond :: Response -> Controller r a -- | Matches on the hostname from the Request. The route only -- succeeds on exact matches. routeHost :: ByteString -> Controller r a -> Controller r () -- | Matches if the path is empty. -- -- Note that this route checks that pathInfo is empty, so it works -- as expected in nested contexts that have popped components from the -- pathInfo list. routeTop :: Controller r a -> Controller r () -- | Matches on the HTTP request method (e.g. GET, POST, -- PUT) routeMethod :: StdMethod -> Controller r a -> Controller r () -- | Matches if the request's Content-Type exactly matches the given string routeAccept :: ByteString -> Controller r a -> Controller r () -- | Routes the given URL pattern. Patterns can include directories as well -- as variable patterns (prefixed with :) to be added to -- queryString (see routeVar) -- -- routePattern :: ByteString -> Controller r a -> Controller r () -- | Matches if the first directory in the path matches the given -- ByteString routeName :: ByteString -> Controller r a -> Controller r () -- | Always matches if there is at least one directory in pathInfo -- but and adds a parameter to queryString where the key is the -- first parameter and the value is the directory consumed from the path. routeVar :: ByteString -> Controller r a -> Controller r () -- | The class of types into which query parameters may be converted class Parseable a -- | Looks up the parameter name in the request's query string and returns -- the Parseable value or Nothing. -- -- For example, for a request with query string: "?foo=bar&baz=7", -- queryParam "foo" would return Just bar, but -- queryParam "zap" would return Nothing. queryParam :: Parseable a => ByteString -> Controller r (Maybe a) -- | Like queryParam, but throws an exception if the parameter is -- not present. queryParam' :: Parseable a => ByteString -> Controller r a -- | Selects all values with the given parameter name queryParams :: Parseable a => ByteString -> Controller r [a] -- | Like queryParam, but further processes the parameter value with -- read. If that conversion fails, an exception is thrown. readQueryParam :: Read a => ByteString -> Controller r (Maybe a) -- | Like readQueryParam, but throws an exception if the parameter -- is not present. readQueryParam' :: Read a => ByteString -> Controller r a -- | Like queryParams, but further processes the parameter values -- with read. If any read-conversion fails, an exception is -- thrown. readQueryParams :: Read a => ByteString -> Controller r [a] -- | Parses a HTML form from the request body. It returns a list of -- Params as well as a list of Files, which are pairs -- mapping the name of a file form field to a FileInfo -- pointing to a temporary file with the contents of the upload. -- --
--   myController = do
--     (prms, files) <- parseForm
--     let mPicFile = lookup "profile_pic" files
--     case mPicFile of
--       Just (picFile) -> do
--         sourceFile (fileContent picFile) $$
--           sinkFile ("images/" ++ (fileName picFile))
--         respond $ redirectTo "/"
--       Nothing -> redirectBack
--   
parseForm :: Controller r ([Param], [(ByteString, FileInfo FilePath)]) -- | Redirect back to the referer. If the referer header is not present -- redirect to root (i.e., /). redirectBack :: Controller r () -- | Redirect back to the referer. If the referer header is not present -- fallback on the given Response. redirectBackOr :: Response -> Controller r () data ControllerException -- | The class of types that can be converted to an Application class ToApplication r toApp :: ToApplication r => r -> Application -- | Lift an application to a controller fromApp :: ToApplication a => a -> Controller r () -- | Reads and returns the body of the HTTP request. body :: Controller r ByteString instance Typeable ControllerException instance Exception ControllerException instance Show ControllerException instance ToApplication Response instance ToApplication Application instance Parseable Text instance Parseable String instance Parseable ByteString instance MonadPeelIO (Controller r) instance MonadIO (Controller r) instance Monad (Controller r) instance Applicative (Controller r) instance Functor (Controller r) -- | Frank is a Sinatra-inspired DSL (see http://www.sinatrarb.com) -- for creating routes. It is composable with all ToApplication -- types, but is designed to be used with Controllers. Each verb -- (get, post, put, etc') takes a URL pattern of the -- form "/dir/:paramname/dir" (see routePattern for details) and a -- ToApplication: -- --
--   main :: IO ()
--   main = run 3000 $ controllerApp () $ do
--     get "/" $ do
--       req <- request
--       return $ okHtml $ fromString $
--         "Welcome Home " ++ (show $ serverName req)
--     get "/user/:id" $ do
--       userId <- queryParam "id" >>= fromMaybe ""
--       return $ ok "text/json" $ fromString $
--         "{\"myid\": " ++ (show userId) ++ "}"
--     put "/user/:id" $ do
--       ...
--   
module Web.Frank -- | Matches the GET method on the given URL pattern get :: ByteString -> Controller r a -> Controller r () -- | Matches the POST method on the given URL pattern post :: ByteString -> Controller r a -> Controller r () -- | Matches the PUT method on the given URL pattern put :: ByteString -> Controller r a -> Controller r () -- | Matches the DELETE method on the given URL pattern delete :: ByteString -> Controller r a -> Controller r () -- | Matches the OPTIONS method on the given URL pattern options :: ByteString -> Controller r a -> Controller r () -- | Provides HTTP Basic Authentication. module Web.Simple.Auth -- | An AuthRouter authenticates a Request and, if -- successful, forwards the Request to the Routeable. type AuthRouter r a = (Request -> ByteString -> ByteString -> Controller r (Maybe Request)) -> Controller r a -> Controller r a -- | An AuthRouter that uses HTTP basic authentication to -- authenticate a request in a particular realm. basicAuthRoute :: String -> AuthRouter r a -- | A Route that uses HTTP basic authentication to authenticate a -- request for a realm with the given username ans password. The request -- is rewritten with an 'X-User' header containing the authenticated -- username before being passed to the next Route. basicAuth :: String -> ByteString -> ByteString -> Controller r a -> Controller r a -- | Wraps an AuthRouter to take a simpler authentication function -- (that just just takes a username and password, and returns True -- or False). It also adds an "X-User" header to the -- Request with the authenticated user's name (the first argument -- to the authentication function). authRewriteReq :: AuthRouter r a -> (ByteString -> ByteString -> Controller r Bool) -> Controller r a -> Controller r a module Web.REST data REST r REST :: Controller r () -> Controller r () -> Controller r () -> Controller r () -> Controller r () -> Controller r () -> Controller r () -> REST r restIndex :: REST r -> Controller r () restShow :: REST r -> Controller r () restCreate :: REST r -> Controller r () restUpdate :: REST r -> Controller r () restDelete :: REST r -> Controller r () restEdit :: REST r -> Controller r () restNew :: REST r -> Controller r () type RESTController r = RESTControllerM r () rest :: RESTControllerM r a -> REST r routeREST :: REST r -> Controller r () index :: Controller r a -> RESTController r show :: Controller r a -> RESTController r create :: Controller r a -> RESTController r update :: Controller r a -> RESTController r delete :: Controller r a -> RESTController r edit :: Controller r a -> RESTController r new :: Controller r a -> RESTController r -- | Simple is based on WAI - an standard interface for -- communicating between web servers (like warp) and web applications. -- You can use Simple completely independently (and of course, use -- any WAI server to run it). Alternatively, you can embed existing -- existing WAI applications inside an app built with Simple, and -- embed an app built with simple in another WAI app. -- -- All the components in Simple are designed to be small and -- simple enough to understand, replaceable, and work as well -- independantly as they do together. module Web.Simple