salvia-0.1: src/Network/Salvia/Core/Handler.hs
{-# LANGUAGE FlexibleInstances, TemplateHaskell #-}
module Network.Salvia.Core.Handler (
Handler
, ResourceHandler
, UriHandler
) where
import Control.Applicative (Applicative, pure, (<*>))
import Control.Monad.State (StateT, ap)
import Network.Protocol.Uri (URI)
import Network.Salvia.Core.Context
import System.IO
{- |
A HTTP request handler lives in `IO` and carries a server context in the
`State` monad. This module also provides an `Applicative` instance for `StateT`
`Context` `IO`.
-}
type Handler a = StateT Context IO a
{- | A resource handler is something that works on some filesystem resource. -}
type ResourceHandler a = FilePath -> Handler a
{- | A URI handler is something that works on an request URI. -}
type UriHandler a = URI -> Handler a
-- Make handlers applicative.
instance Applicative (StateT Context IO) where
pure = return
(<*>) = ap