Yesod.Core.Dispatch

yesod-core-1.4.30: Creation of type-safe, RESTful web applications.

Safe Haskell | None
Language | Haskell98

Yesod.Core.Dispatch

Contents

- Quasi-quoted routing
  - More fine-grained
    - Helpers
  - Path pieces
- Convert to WAI
- WAI subsites

Synopsis

- parseRoutes :: QuasiQuoter
- parseRoutesNoCheck :: QuasiQuoter
- parseRoutesFile :: FilePath -> Q Exp
- parseRoutesFileNoCheck :: FilePath -> Q Exp
- mkYesod :: String -> [ResourceTree String] -> Q [Dec]
- mkYesodWith :: String -> [Either String [String]] -> [ResourceTree String] -> Q [Dec]
- mkYesodData :: String -> [ResourceTree String] -> Q [Dec]
- mkYesodSubData :: String -> [ResourceTree String] -> Q [Dec]
- mkYesodDispatch :: String -> [ResourceTree String] -> Q [Dec]
- mkYesodSubDispatch :: [ResourceTree a] -> Q Exp
- getGetMaxExpires :: IO (IO Text)
- class PathPiece s where
  - fromPathPiece :: Text -> Maybe s
  - toPathPiece :: s -> Text
- class PathMultiPiece s where
  - fromPathMultiPiece :: [Text] -> Maybe s
  - toPathMultiPiece :: s -> [Text]
- type Texts = [Text]
- toWaiApp :: YesodDispatch site => site -> IO Application
- toWaiAppPlain :: YesodDispatch site => site -> IO Application
- toWaiAppYre :: YesodDispatch site => YesodRunnerEnv site -> Application
- warp :: YesodDispatch site => Int -> site -> IO ()
- warpDebug :: YesodDispatch site => Int -> site -> IO ()
- warpEnv :: YesodDispatch site => site -> IO ()
- mkDefaultMiddlewares :: Logger -> IO Middleware
- defaultMiddlewaresNoLogging :: Middleware
- newtype WaiSubsite = WaiSubsite {
  - runWaiSubsite :: Application
  }
- subHelper :: Monad m => HandlerT child (HandlerT parent m) TypedContent -> YesodSubRunnerEnv child parent (HandlerT parent m) -> Maybe (Route child) -> Application

# Quasi-quoted routing

parseRoutes :: QuasiQuoter #

A quasi-quoter to parse a string into a list of `Resource`s. Checks for overlapping routes, failing if present; use `parseRoutesNoCheck` to skip the checking. See documentation site for details on syntax.

parseRoutesNoCheck :: QuasiQuoter #

Same as `parseRoutes`, but performs no overlap checking.

parseRoutesFile :: FilePath -> Q Exp #

parseRoutesFileNoCheck :: FilePath -> Q Exp #

mkYesod #

Arguments

:: String | name of the argument datatype
-> [ResourceTree String] |
-> Q [Dec] |

Generates URL datatype and site function for the given `Resource`s. This is used for creating sites, not subsites. See `mkYesodSub` for the latter. Use `parseRoutes` to create the `Resource`s.

mkYesodWith :: String -> [Either String [String]] -> [ResourceTree String] -> Q [Dec] #

## More fine-grained

mkYesodData :: String -> [ResourceTree String] -> Q [Dec] #

Sometimes, you will want to declare your routes in one file and define your handlers elsewhere. For example, this is the only way to break up a monolithic file into smaller parts. Use this function, paired with `mkYesodDispatch`, to do just that.

mkYesodSubData :: String -> [ResourceTree String] -> Q [Dec] #

mkYesodDispatch :: String -> [ResourceTree String] -> Q [Dec] #

See `mkYesodData`.

mkYesodSubDispatch :: [ResourceTree a] -> Q Exp #

### Helpers

getGetMaxExpires :: IO (IO Text) #

Default constructor for `yreGetMaxExpires` field. Low level function for simple manual construction of `YesodRunnerEnv`.

Since: 1.4.29

## Path pieces

class PathPiece s where #

Instances

PathPiece Bool |
Methods fromPathPiece :: Text -> Maybe Bool # toPathPiece :: Bool -> Text #
PathPiece Int |
Methods fromPathPiece :: Text -> Maybe Int # toPathPiece :: Int -> Text #
PathPiece Int8 |
Methods fromPathPiece :: Text -> Maybe Int8 # toPathPiece :: Int8 -> Text #
PathPiece Int16 |
Methods fromPathPiece :: Text -> Maybe Int16 # toPathPiece :: Int16 -> Text #
PathPiece Int32 |
Methods fromPathPiece :: Text -> Maybe Int32 # toPathPiece :: Int32 -> Text #
PathPiece Int64 |
Methods fromPathPiece :: Text -> Maybe Int64 # toPathPiece :: Int64 -> Text #
PathPiece Integer |
Methods fromPathPiece :: Text -> Maybe Integer # toPathPiece :: Integer -> Text #
PathPiece Word |
Methods fromPathPiece :: Text -> Maybe Word # toPathPiece :: Word -> Text #
PathPiece Word8 |
Methods fromPathPiece :: Text -> Maybe Word8 # toPathPiece :: Word8 -> Text #
PathPiece Word16 |
Methods fromPathPiece :: Text -> Maybe Word16 # toPathPiece :: Word16 -> Text #
PathPiece Word32 |
Methods fromPathPiece :: Text -> Maybe Word32 # toPathPiece :: Word32 -> Text #
PathPiece Word64 |
Methods fromPathPiece :: Text -> Maybe Word64 # toPathPiece :: Word64 -> Text #
PathPiece () |
Methods fromPathPiece :: Text -> Maybe () # toPathPiece :: () -> Text #
PathPiece Text |
Methods fromPathPiece :: Text -> Maybe Text # toPathPiece :: Text -> Text #
PathPiece String |
Methods fromPathPiece :: Text -> Maybe String # toPathPiece :: String -> Text #
PathPiece Text |
Methods fromPathPiece :: Text -> Maybe Text # toPathPiece :: Text -> Text #
PathPiece Day |
Methods fromPathPiece :: Text -> Maybe Day # toPathPiece :: Day -> Text #
PathPiece a => PathPiece (Maybe a) |
Methods fromPathPiece :: Text -> Maybe (Maybe a) # toPathPiece :: Maybe a -> Text #

class PathMultiPiece s where #

Instances

PathPiece a => PathMultiPiece [a] |
Methods fromPathMultiPiece :: [Text] -> Maybe [a] # toPathMultiPiece :: [a] -> [Text] #

type Texts = [Text] #

# Convert to WAI

toWaiApp :: YesodDispatch site => site -> IO Application #

Same as `toWaiAppPlain`, but provides a default set of middlewares. This set may change with future releases, but currently covers:

- Logging
- GZIP compression
- Automatic HEAD method handling
- Request method override with the _method query string parameter
- Accept header override with the _accept query string parameter

toWaiAppPlain :: YesodDispatch site => site -> IO Application #

Convert the given argument into a WAI application, executable with any WAI handler. This function will provide no middlewares; if you want commonly used middlewares, please use `toWaiApp`.

toWaiAppYre :: YesodDispatch site => YesodRunnerEnv site -> Application #

Pure low level function to construct WAI application. Usefull when you need not standard way to run your app, or want to embed it inside another app.

Since: 1.4.29

warp :: YesodDispatch site => Int -> site -> IO () #

A convenience method to run an application using the Warp webserver on the specified port. Automatically calls `toWaiApp`. Provides a default set of middlewares. This set may change at any point without a breaking version number. Currently, it includes:

If you need more fine-grained control of middlewares, please use `toWaiApp` directly.

Since 1.2.0

warpDebug :: YesodDispatch site => Int -> site -> IO () #

Deprecated: Please use warp instead

Deprecated synonym for `warp`.

warpEnv :: YesodDispatch site => site -> IO () #

Runs your application using default middlewares (i.e., via `toWaiApp`). It reads port information from the PORT environment variable, as used by tools such as Keter and the FP Complete School of Haskell.

Note that the exact behavior of this function may be modified slightly over time to work correctly with external tools, without a change to the type signature.

mkDefaultMiddlewares :: Logger -> IO Middleware #

A default set of middlewares.

Since 1.2.0

defaultMiddlewaresNoLogging :: Middleware #

All of the default middlewares, excluding logging.

Since 1.2.12

# WAI subsites

newtype WaiSubsite #

Wrap up a normal WAI application as a Yesod subsite.

Constructors

WaiSubsite |
Fields runWaiSubsite :: Application

Instances

ParseRoute WaiSubsite # |
Methods parseRoute :: ([Text], [(Text, Text)]) -> Maybe (Route WaiSubsite) #
RenderRoute WaiSubsite # |
Associated Types data Route WaiSubsite :: * # Methods renderRoute :: Route WaiSubsite -> ([Text], [(Text, Text)]) #
YesodSubDispatch WaiSubsite master # |
Methods yesodSubDispatch :: YesodSubRunnerEnv WaiSubsite (HandlerSite master) master -> Application #
Eq (Route WaiSubsite) # |
Methods (==) :: Route WaiSubsite -> Route WaiSubsite -> Bool # (/=) :: Route WaiSubsite -> Route WaiSubsite -> Bool #
Ord (Route WaiSubsite) # |
Methods compare :: Route WaiSubsite -> Route WaiSubsite -> Ordering # (<) :: Route WaiSubsite -> Route WaiSubsite -> Bool # (<=) :: Route WaiSubsite -> Route WaiSubsite -> Bool # (>) :: Route WaiSubsite -> Route WaiSubsite -> Bool # (>=) :: Route WaiSubsite -> Route WaiSubsite -> Bool # max :: Route WaiSubsite -> Route WaiSubsite -> Route WaiSubsite # min :: Route WaiSubsite -> Route WaiSubsite -> Route WaiSubsite #
Read (Route WaiSubsite) # |
Methods readsPrec :: Int -> ReadS (Route WaiSubsite) # readList :: ReadS [Route WaiSubsite] # readPrec :: ReadPrec (Route WaiSubsite) # readListPrec :: ReadPrec [Route WaiSubsite] #
Show (Route WaiSubsite) # |
Methods showsPrec :: Int -> Route WaiSubsite -> ShowS # show :: Route WaiSubsite -> String # showList :: [Route WaiSubsite] -> ShowS #
data Route WaiSubsite # |
data Route WaiSubsite = WaiSubsiteRoute [Text] [(Text, Text)]

subHelper :: Monad m => HandlerT child (HandlerT parent m) TypedContent -> YesodSubRunnerEnv child parent (HandlerT parent m) -> Maybe (Route child) -> Application #

A helper function for creating YesodSubDispatch instances, used by the internal generated code. This function has been exported since 1.4.11. It promotes a subsite handler to a wai application.