{-# LANGUAGE OverloadedStrings, RankNTypes #-}
module Web.Scotty
(
scotty, scottyApp, scottyOpts, scottySocket, Options(..), defaultOptions
, middleware, get, post, put, delete, patch, options, addroute, matchAny, notFound, nested, setMaxRequestBodySize
, capture, regex, function, literal
, request, header, headers, body, bodyReader
, param, params
, captureParam, formParam, queryParam
, captureParams, formParams, queryParams
, jsonData, files
, status, addHeader, setHeader, redirect
, text, html, file, json, stream, raw
, raise, raiseStatus, throw, rescue, next, finish, defaultHandler, liftAndCatchIO
, StatusError(..)
, Param, Trans.Parsable(..), Trans.readEither
, ScottyM, ActionM, RoutePattern, File, Kilobytes, Handler(..)
, ScottyState, defaultScottyState
) where
import qualified Web.Scotty.Trans as Trans
import qualified Control.Exception as E
import Data.Aeson (FromJSON, ToJSON)
import qualified Data.ByteString as BS
import Data.ByteString.Lazy.Char8 (ByteString)
import Data.Text.Lazy (Text)
import Network.HTTP.Types (Status, StdMethod)
import Network.Socket (Socket)
import Network.Wai (Application, Middleware, Request, StreamingBody)
import Network.Wai.Handler.Warp (Port)
import Web.Scotty.Internal.Types (ScottyT, ActionT, ErrorHandler, Param, RoutePattern, Options, defaultOptions, File, Kilobytes, ScottyState, defaultScottyState, StatusError(..))
import Web.Scotty.Exceptions (Handler(..))
type ScottyM = ScottyT IO
type ActionM = ActionT IO
scotty :: Port -> ScottyM () -> IO ()
scotty :: Port -> ScottyM () -> IO ()
scotty Port
p = Port -> (IO Response -> IO Response) -> ScottyM () -> IO ()
forall (m :: * -> *) (n :: * -> *).
(Monad m, MonadIO n) =>
Port -> (m Response -> IO Response) -> ScottyT m () -> n ()
Trans.scottyT Port
p IO Response -> IO Response
forall a. a -> a
id
scottyOpts :: Options -> ScottyM () -> IO ()
scottyOpts :: Options -> ScottyM () -> IO ()
scottyOpts Options
opts = Options -> (IO Response -> IO Response) -> ScottyM () -> IO ()
forall (m :: * -> *) (n :: * -> *).
(Monad m, MonadIO n) =>
Options -> (m Response -> IO Response) -> ScottyT m () -> n ()
Trans.scottyOptsT Options
opts IO Response -> IO Response
forall a. a -> a
id
scottySocket :: Options -> Socket -> ScottyM () -> IO ()
scottySocket :: Options -> Socket -> ScottyM () -> IO ()
scottySocket Options
opts Socket
sock = Options
-> Socket -> (IO Response -> IO Response) -> ScottyM () -> IO ()
forall (m :: * -> *) (n :: * -> *).
(Monad m, MonadIO n) =>
Options
-> Socket -> (m Response -> IO Response) -> ScottyT m () -> n ()
Trans.scottySocketT Options
opts Socket
sock IO Response -> IO Response
forall a. a -> a
id
scottyApp :: ScottyM () -> IO Application
scottyApp :: ScottyM () -> IO Application
scottyApp = (IO Response -> IO Response) -> ScottyM () -> IO Application
forall (m :: * -> *) (n :: * -> *).
(Monad m, Monad n) =>
(m Response -> IO Response) -> ScottyT m () -> n Application
Trans.scottyAppT IO Response -> IO Response
forall a. a -> a
id
defaultHandler :: ErrorHandler IO -> ScottyM ()
defaultHandler :: ErrorHandler IO -> ScottyM ()
defaultHandler = ErrorHandler IO -> ScottyM ()
forall (m :: * -> *). Monad m => ErrorHandler m -> ScottyT m ()
Trans.defaultHandler
middleware :: Middleware -> ScottyM ()
middleware :: Middleware -> ScottyM ()
middleware = Middleware -> ScottyM ()
forall (m :: * -> *). Middleware -> ScottyT m ()
Trans.middleware
nested :: Application -> ActionM ()
nested :: Application -> ActionM ()
nested = Application -> ActionM ()
forall (m :: * -> *). MonadIO m => Application -> ActionT m ()
Trans.nested
setMaxRequestBodySize :: Kilobytes -> ScottyM ()
setMaxRequestBodySize :: Port -> ScottyM ()
setMaxRequestBodySize = Port -> ScottyM ()
forall (m :: * -> *). Port -> ScottyT m ()
Trans.setMaxRequestBodySize
raise :: Text -> ActionM a
raise :: forall a. Text -> ActionM a
raise = Text -> ActionT IO a
forall (m :: * -> *) a. MonadIO m => Text -> ActionT m a
Trans.raise
raiseStatus :: Status -> Text -> ActionM a
raiseStatus :: forall a. Status -> Text -> ActionM a
raiseStatus = Status -> Text -> ActionT IO a
forall (m :: * -> *) a. Monad m => Status -> Text -> ActionT m a
Trans.raiseStatus
throw :: (E.Exception e) => e -> ActionM a
throw :: forall e a. Exception e => e -> ActionM a
throw = e -> ActionT IO a
forall (m :: * -> *) e a.
(MonadIO m, Exception e) =>
e -> ActionT m a
Trans.throw
next :: ActionM ()
next :: ActionM ()
next = ActionM ()
forall (m :: * -> *) a. Monad m => ActionT m a
Trans.next
finish :: ActionM a
finish :: forall a. ActionM a
finish = ActionT IO a
forall (m :: * -> *) a. Monad m => ActionT m a
Trans.finish
rescue :: E.Exception e => ActionM a -> (e -> ActionM a) -> ActionM a
rescue :: forall e a.
Exception e =>
ActionM a -> (e -> ActionM a) -> ActionM a
rescue = ActionT IO a -> (e -> ActionT IO a) -> ActionT IO a
forall (m :: * -> *) e a.
(MonadUnliftIO m, Exception e) =>
ActionT m a -> (e -> ActionT m a) -> ActionT m a
Trans.rescue
liftAndCatchIO :: IO a -> ActionM a
liftAndCatchIO :: forall a. IO a -> ActionM a
liftAndCatchIO = IO a -> ActionT IO a
forall (m :: * -> *) a. MonadIO m => IO a -> ActionT m a
Trans.liftAndCatchIO
redirect :: Text -> ActionM a
redirect :: forall a. Text -> ActionM a
redirect = Text -> ActionT IO a
forall (m :: * -> *) a. Monad m => Text -> ActionT m a
Trans.redirect
request :: ActionM Request
request :: ActionM Request
request = ActionM Request
forall (m :: * -> *). Monad m => ActionT m Request
Trans.request
files :: ActionM [File]
files :: ActionM [File]
files = ActionM [File]
forall (m :: * -> *). Monad m => ActionT m [File]
Trans.files
header :: Text -> ActionM (Maybe Text)
= Text -> ActionM (Maybe Text)
forall (m :: * -> *). Monad m => Text -> ActionT m (Maybe Text)
Trans.header
headers :: ActionM [(Text, Text)]
= ActionM [(Text, Text)]
forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.headers
body :: ActionM ByteString
body :: ActionM ByteString
body = ActionM ByteString
forall (m :: * -> *). MonadIO m => ActionT m ByteString
Trans.body
bodyReader :: ActionM (IO BS.ByteString)
bodyReader :: ActionM (IO ByteString)
bodyReader = ActionM (IO ByteString)
forall (m :: * -> *). Monad m => ActionT m (IO ByteString)
Trans.bodyReader
jsonData :: FromJSON a => ActionM a
jsonData :: forall a. FromJSON a => ActionM a
jsonData = ActionT IO a
forall a (m :: * -> *). (FromJSON a, MonadIO m) => ActionT m a
Trans.jsonData
param :: Trans.Parsable a => Text -> ActionM a
param :: forall a. Parsable a => Text -> ActionM a
param = Text -> ActionT IO a
forall a (m :: * -> *).
(Parsable a, MonadIO m) =>
Text -> ActionT m a
Trans.param
{-# DEPRECATED param "(#204) Not a good idea to treat all parameters identically. Use captureParam, formParam and queryParam instead. "#-}
captureParam :: Trans.Parsable a => Text -> ActionM a
captureParam :: forall a. Parsable a => Text -> ActionM a
captureParam = Text -> ActionT IO a
forall a (m :: * -> *).
(Parsable a, Monad m) =>
Text -> ActionT m a
Trans.captureParam
formParam :: Trans.Parsable a => Text -> ActionM a
formParam :: forall a. Parsable a => Text -> ActionM a
formParam = Text -> ActionT IO a
forall a (m :: * -> *).
(Parsable a, Monad m) =>
Text -> ActionT m a
Trans.formParam
queryParam :: Trans.Parsable a => Text -> ActionM a
queryParam :: forall a. Parsable a => Text -> ActionM a
queryParam = Text -> ActionT IO a
forall a (m :: * -> *).
(Parsable a, Monad m) =>
Text -> ActionT m a
Trans.queryParam
params :: ActionM [Param]
params :: ActionM [(Text, Text)]
params = ActionM [(Text, Text)]
forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.params
{-# DEPRECATED params "(#204) Not a good idea to treat all parameters identically. Use captureParams, formParams and queryParams instead. "#-}
captureParams :: ActionM [Param]
captureParams :: ActionM [(Text, Text)]
captureParams = ActionM [(Text, Text)]
forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.captureParams
formParams :: ActionM [Param]
formParams :: ActionM [(Text, Text)]
formParams = ActionM [(Text, Text)]
forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.formParams
queryParams :: ActionM [Param]
queryParams :: ActionM [(Text, Text)]
queryParams = ActionM [(Text, Text)]
forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.queryParams
status :: Status -> ActionM ()
status :: Status -> ActionM ()
status = Status -> ActionM ()
forall (m :: * -> *). MonadIO m => Status -> ActionT m ()
Trans.status
addHeader :: Text -> Text -> ActionM ()
= Text -> Text -> ActionM ()
forall (m :: * -> *). MonadIO m => Text -> Text -> ActionT m ()
Trans.addHeader
setHeader :: Text -> Text -> ActionM ()
= Text -> Text -> ActionM ()
forall (m :: * -> *). MonadIO m => Text -> Text -> ActionT m ()
Trans.setHeader
text :: Text -> ActionM ()
text :: Text -> ActionM ()
text = Text -> ActionM ()
forall (m :: * -> *). MonadIO m => Text -> ActionT m ()
Trans.text
html :: Text -> ActionM ()
html :: Text -> ActionM ()
html = Text -> ActionM ()
forall (m :: * -> *). MonadIO m => Text -> ActionT m ()
Trans.html
file :: FilePath -> ActionM ()
file :: FilePath -> ActionM ()
file = FilePath -> ActionM ()
forall (m :: * -> *). MonadIO m => FilePath -> ActionT m ()
Trans.file
json :: ToJSON a => a -> ActionM ()
json :: forall a. ToJSON a => a -> ActionM ()
json = a -> ActionM ()
forall a (m :: * -> *). (ToJSON a, MonadIO m) => a -> ActionT m ()
Trans.json
stream :: StreamingBody -> ActionM ()
stream :: StreamingBody -> ActionM ()
stream = StreamingBody -> ActionM ()
forall (m :: * -> *). MonadIO m => StreamingBody -> ActionT m ()
Trans.stream
raw :: ByteString -> ActionM ()
raw :: ByteString -> ActionM ()
raw = ByteString -> ActionM ()
forall (m :: * -> *). MonadIO m => ByteString -> ActionT m ()
Trans.raw
get :: RoutePattern -> ActionM () -> ScottyM ()
get :: RoutePattern -> ActionM () -> ScottyM ()
get = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.get
post :: RoutePattern -> ActionM () -> ScottyM ()
post :: RoutePattern -> ActionM () -> ScottyM ()
post = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.post
put :: RoutePattern -> ActionM () -> ScottyM ()
put :: RoutePattern -> ActionM () -> ScottyM ()
put = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.put
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.delete
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.patch
options :: RoutePattern -> ActionM () -> ScottyM ()
options :: RoutePattern -> ActionM () -> ScottyM ()
options = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.options
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny = RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.matchAny
notFound :: ActionM () -> ScottyM ()
notFound :: ActionM () -> ScottyM ()
notFound = ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
ActionT m () -> ScottyT m ()
Trans.notFound
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute = StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
forall (m :: * -> *).
MonadUnliftIO m =>
StdMethod -> RoutePattern -> ActionT m () -> ScottyT m ()
Trans.addroute
regex :: String -> RoutePattern
regex :: FilePath -> RoutePattern
regex = FilePath -> RoutePattern
Trans.regex
capture :: String -> RoutePattern
capture :: FilePath -> RoutePattern
capture = FilePath -> RoutePattern
Trans.capture
function :: (Request -> Maybe [Param]) -> RoutePattern
function :: (Request -> Maybe [(Text, Text)]) -> RoutePattern
function = (Request -> Maybe [(Text, Text)]) -> RoutePattern
Trans.function
literal :: String -> RoutePattern
literal :: FilePath -> RoutePattern
literal = FilePath -> RoutePattern
Trans.literal