printRqContextPath :: Snap () printRqContextPath = writeBS . rqContextPath =<< getRequest
printRspStatusReason :: Snap () printRspStatusReason = writeBS . rspStatusReason =<< getResponse
a :: Snap String a = pass b :: Snap String b = return "foo" c :: Snap String c = a <|> b -- try running a, if it fails then try b
example :: (OutputStream Builder -> IO (OutputStream Builder)) -> Snap () example streamProc = do writeBS "I'm a strict bytestring" writeLBS "I'm a lazy bytestring" writeText "I'm strict text" addToOutput streamProc
a :: Snap () a = do modifyResponse $ setResponseStatus 500 "Internal Server Error" writeBS "500 error" r <- getResponse finishWith rthen any subsequent processing will be skipped and the supplied Response value will be returned from runSnap as-is.
a :: Snap () a = liftIO fireTheMissiles
a :: Snap () a = setTimeout 30
import Control.Exception.Lifted (SomeException, throwIO, catch) foo :: Snap () foo = bar `catch` (e::SomeException) -> baz where bar = throwIO FooException
foo :: Snap () foo = logError "grumble."
printRqContextPath :: Snap () printRqContextPath = writeBS . rqContextPath =<< getRequest
printRspStatusReason :: Snap () printRspStatusReason = writeBS . rspStatusReason =<< getResponse
a :: Snap String a = pass b :: Snap String b = return "foo" c :: Snap String c = a <|> b -- try running a, if it fails then try b
example :: (OutputStream Builder -> IO (OutputStream Builder)) -> Snap () example streamProc = do writeBS "I'm a strict bytestring" writeLBS "I'm a lazy bytestring" writeText "I'm strict text" addToOutput streamProc
a :: Snap () a = do modifyResponse $ setResponseStatus 500 "Internal Server Error" writeBS "500 error" r <- getResponse finishWith rthen any subsequent processing will be skipped and the supplied Response value will be returned from runSnap as-is.
a :: Snap () a = liftIO fireTheMissiles
a :: Snap () a = setTimeout 30
import Control.Exception.Lifted (SomeException, throwIO, catch) foo :: Snap () foo = bar `catch` (e::SomeException) -> baz where bar = throwIO FooException
foo :: Snap () foo = logError "grumble."
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> let br = bracketSnap (putStrLn "before") (const $ putStrLn "after") ghci> T.runHandler (T.get "/" M.empty) (br $ const $ writeBS "OK") before after HTTP/1.1 200 OK server: Snap/test date: Thu, 07 Aug 2014 18:41:50 GMT OK