{-# LANGUAGE OverloadedStrings, RankNTypes #-}
module Web.Scotty
(
scotty, scottyApp, scottyOpts, Options(..)
, middleware, get, post, put, delete, patch, addroute, matchAny, notFound
, capture, regex, function, literal
, request, header, headers, body, param, params, jsonData, files
, status, addHeader, setHeader, redirect
, text, html, file, json, stream, source, raw
, raise, rescue, next, defaultHandler
, Param, Trans.Parsable(..), Trans.readEither
, ScottyM, ActionM, RoutePattern, File
) where
import qualified Web.Scotty.Trans as Trans
import qualified Web.Scotty.Action as Action
import Blaze.ByteString.Builder (Builder)
import Data.Aeson (FromJSON, ToJSON)
import Data.ByteString.Lazy.Char8 (ByteString)
import Data.Text.Lazy (Text)
import Data.Conduit (Flush, Source)
import Network.HTTP.Types (Status, StdMethod)
import Network.Wai (Application, Middleware, Request, StreamingBody)
import Network.Wai.Handler.Warp (Port)
import Web.Scotty.Internal.Types (ScottyT, ActionT, Param, RoutePattern, Options, File)
type ScottyM = ScottyT Text IO
type ActionM = ActionT Text IO
scotty :: Port -> ScottyM () -> IO ()
scotty p = Trans.scottyT p id id
scottyOpts :: Options -> ScottyM () -> IO ()
scottyOpts opts = Trans.scottyOptsT opts id id
scottyApp :: ScottyM () -> IO Application
scottyApp = Trans.scottyAppT id id
defaultHandler :: (Text -> ActionM ()) -> ScottyM ()
defaultHandler = Trans.defaultHandler
middleware :: Middleware -> ScottyM ()
middleware = Trans.middleware
raise :: Text -> ActionM a
raise = Trans.raise
next :: ActionM a
next = Trans.next
rescue :: ActionM a -> (Text -> ActionM a) -> ActionM a
rescue = Trans.rescue
redirect :: Text -> ActionM a
redirect = Trans.redirect
request :: ActionM Request
request = Trans.request
files :: ActionM [File]
files = Trans.files
header :: Text -> ActionM (Maybe Text)
header = Trans.header
headers :: ActionM [(Text, Text)]
headers = Trans.headers
body :: ActionM ByteString
body = Trans.body
jsonData :: FromJSON a => ActionM a
jsonData = Trans.jsonData
param :: Trans.Parsable a => Text -> ActionM a
param = Trans.param
params :: ActionM [Param]
params = Trans.params
status :: Status -> ActionM ()
status = Trans.status
addHeader :: Text -> Text -> ActionM ()
addHeader = Trans.addHeader
setHeader :: Text -> Text -> ActionM ()
setHeader = Trans.setHeader
text :: Text -> ActionM ()
text = Trans.text
html :: Text -> ActionM ()
html = Trans.html
file :: FilePath -> ActionM ()
file = Trans.file
json :: ToJSON a => a -> ActionM ()
json = Trans.json
stream :: StreamingBody -> ActionM ()
stream = Trans.stream
source :: Source IO (Flush Builder) -> ActionM ()
source = Action.source
{-# DEPRECATED source "Use 'stream' instead. This will be removed in the next release." #-}
raw :: ByteString -> ActionM ()
raw = Trans.raw
get :: RoutePattern -> ActionM () -> ScottyM ()
get = Trans.get
post :: RoutePattern -> ActionM () -> ScottyM ()
post = Trans.post
put :: RoutePattern -> ActionM () -> ScottyM ()
put = Trans.put
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete = Trans.delete
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch = Trans.patch
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny = Trans.matchAny
notFound :: ActionM () -> ScottyM ()
notFound = Trans.notFound
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute = Trans.addroute
regex :: String -> RoutePattern
regex = Trans.regex
capture :: String -> RoutePattern
capture = Trans.capture
function :: (Request -> Maybe [Param]) -> RoutePattern
function = Trans.function
literal :: String -> RoutePattern
literal = Trans.literal