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

Safe Haskell | None
Language | Haskell2010

Yesod.Core.Unsafe

Description

This is designed to be used as

    import qualified Yesod.Core.Unsafe as Unsafe

This serves as a reminder that the functions are unsafe to use in many situations.

Synopsis

- runFakeHandler :: (Yesod site, MonadIO m) => SessionMap -> (site -> Logger) -> site -> HandlerFor site a -> m (Either ErrorResponse a)
- fakeHandlerGetLogger :: (Yesod site, MonadIO m) => (site -> Logger) -> site -> HandlerFor site a -> m a

# Documentation

runFakeHandler :: (Yesod site, MonadIO m) => SessionMap -> (site -> Logger) -> site -> HandlerFor site a -> m (Either ErrorResponse a) Source #

Run a `HandlerFor` completely outside of Yesod. This function comes with many caveats and you shouldn't use it unless you fully understand what it's doing and how it works.

As of now, there's only one reason to use this function at all: in order to run unit tests of functions inside `HandlerFor` but that aren't easily testable with a full HTTP request. Even so, it's better to use `wai-test` or `yesod-test` instead of using this function.

This function will create a fake HTTP request (both `wai`'s `Request` and `yesod`'s `Request`) and feed it to the `HandlerFor`. The only useful information the `HandlerFor` may get from the request is the session map, which you must supply as argument to `runFakeHandler`. All other fields contain fake information, which means that they can be accessed but won't have any useful information. The response of the `HandlerFor` is completely ignored, including changes to the session, cookies or headers. We only return you the `HandlerFor`'s return value.

fakeHandlerGetLogger :: (Yesod site, MonadIO m) => (site -> Logger) -> site -> HandlerFor site a -> m a Source #

designed to be used as

    unsafeHandler = Unsafe.fakeHandlerGetLogger appLogger