snap -is:package

Event source with a single occurrence at time 0. The value of the event is obtained by sampling the input at that time.
Snap is the Monad that user web handlers run in. Snap gives you:
  1. Stateful access to fetch or modify an HTTP Request.
    printRqContextPath :: Snap () printRqContextPath =
    writeBS . rqContextPath =<< getRequest
    
  2. Stateful access to fetch or modify an HTTP Response.
    printRspStatusReason :: Snap ()
    printRspStatusReason = writeBS . rspStatusReason
    =<< getResponse 
  3. Failure / Alternative / MonadPlus semantics: a Snap handler can choose not to handle a given request, using empty or its synonym pass, and you can try alternative handlers with the <|> operator:
    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
    
  4. Convenience functions (writeBS, writeLBS, writeText, writeLazyText, addToOutput) for queueing output to be written to the Response, or for streaming to the response using io-streams:
    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
    
  5. Early termination: if you call finishWith:
    a :: Snap ()
    a = do modifyResponse $ setResponseStatus 500 "Internal
    Server Error" writeBS "500 error" r <- getResponse
    finishWith r 
    then any subsequent processing will be skipped and the supplied Response value will be returned from runSnap as-is.
  6. Access to the IO monad through a MonadIO instance:
    a :: Snap () a = liftIO fireTheMissiles
    
  7. The ability to set or extend a timeout which will kill the handler thread after N seconds of inactivity (the default is 20 seconds):
    a :: Snap () a = setTimeout 30 
  8. Throw and catch exceptions using a MonadBaseControl instance:
    import Control.Exception.Lifted
    (SomeException, throwIO, catch) foo :: Snap ()
    foo = bar `catch` (e::SomeException) -> baz where bar =
    throwIO FooException 
  9. Log a message to the error log:
    foo :: Snap () foo =
    logError "grumble." 
You may notice that most of the type signatures in this module contain a (MonadSnap m) => ... typeclass constraint. MonadSnap is a typeclass which, in essence, says "you can get back to the Snap monad from here". Using MonadSnap you can extend the Snap monad with additional functionality and still have access to most of the Snap functions without writing lift everywhere. Instances are already provided for most of the common monad transformers (ReaderT, WriterT, StateT, etc.).
Snap is the Monad that user web handlers run in. Snap gives you:
  1. Stateful access to fetch or modify an HTTP Request.
    printRqContextPath :: Snap () printRqContextPath =
    writeBS . rqContextPath =<< getRequest
    
  2. Stateful access to fetch or modify an HTTP Response.
    printRspStatusReason :: Snap ()
    printRspStatusReason = writeBS . rspStatusReason
    =<< getResponse 
  3. Failure / Alternative / MonadPlus semantics: a Snap handler can choose not to handle a given request, using empty or its synonym pass, and you can try alternative handlers with the <|> operator:
    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
    
  4. Convenience functions (writeBS, writeLBS, writeText, writeLazyText, addToOutput) for queueing output to be written to the Response, or for streaming to the response using io-streams:
    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
    
  5. Early termination: if you call finishWith:
    a :: Snap ()
    a = do modifyResponse $ setResponseStatus 500 "Internal
    Server Error" writeBS "500 error" r <- getResponse
    finishWith r 
    then any subsequent processing will be skipped and the supplied Response value will be returned from runSnap as-is.
  6. Access to the IO monad through a MonadIO instance:
    a :: Snap () a = liftIO fireTheMissiles
    
  7. The ability to set or extend a timeout which will kill the handler thread after N seconds of inactivity (the default is 20 seconds):
    a :: Snap () a = setTimeout 30 
  8. Throw and catch exceptions using a MonadBaseControl instance:
    import Control.Exception.Lifted
    (SomeException, throwIO, catch) foo :: Snap ()
    foo = bar `catch` (e::SomeException) -> baz where bar =
    throwIO FooException 
  9. Log a message to the error log:
    foo :: Snap () foo =
    logError "grumble." 
You may notice that most of the type signatures in this module contain a (MonadSnap m) => ... typeclass constraint. MonadSnap is a typeclass which, in essence, says "you can get back to the Snap monad from here". Using MonadSnap you can extend the Snap monad with additional functionality and still have access to most of the Snap functions without writing lift everywhere. Instances are already provided for most of the common monad transformers (ReaderT, WriterT, StateT, etc.).
This module provides convenience exports of the modules most commonly used when developing with the Snap Framework. For documentation about Snaplets, see Snap.Snaplet. For the core web server API, see Snap.Core.
Snap integration for the WebSockets library
Modifies a PackageDescription by appending a snapshot number corresponding to the given date.
Modifies a Version by appending a snapshot number corresponding to the given date.
Constructs a url relative to the current snaplet.
A short string describing the Snap server version
Take an atomic snapshot of the current state of the virtual file system.
Appends a stroked border rectangle inside the given outline. The four sides of the border can have different widths and colors.
Creates a new CairoNode and appends it to the current render node of snapshot, without changing the current node.
Creates a new render node drawing the color into the given bounds and appends it to the current render node of snapshot. You should try to avoid calling this function if color is transparent.
Appends a conic gradient node with the given stops to snapshot.
A convenience method to fill a path with a color. See snapshotPushFill if you need to fill a path with more complex content than a color. Since: 4.14
Appends an inset shadow into the box given by outline.
Creates render nodes for rendering layout in the given foregound color and appends them to the current node of snapshot without changing the current node. The current theme's foreground color for a widget can be obtained with widgetGetColor. Note that if the layout does not produce any visible output, then nodes may not be added to the snapshot.
Appends a linear gradient node with the given stops to snapshot.
Appends node to the current render node of snapshot, without changing the current node. If snapshot does not have a current node yet, node will become the initial node.
Appends an outset shadow node around the box given by outline.
Appends a radial gradient node with the given stops to snapshot.
Appends a repeating linear gradient node with the given stops to snapshot.