{-# 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 = forall (m :: * -> *) (n :: * -> *).
(Monad m, MonadIO n) =>
Port -> (m Response -> IO Response) -> ScottyT m () -> n ()
Trans.scottyT Port
p forall a. a -> a
id
scottyOpts :: Options -> ScottyM () -> IO ()
scottyOpts :: Options -> ScottyM () -> IO ()
scottyOpts Options
opts = forall (m :: * -> *) (n :: * -> *).
(Monad m, MonadIO n) =>
Options -> (m Response -> IO Response) -> ScottyT m () -> n ()
Trans.scottyOptsT Options
opts forall a. a -> a
id
scottySocket :: Options -> Socket -> ScottyM () -> IO ()
scottySocket :: Options -> Socket -> ScottyM () -> IO ()
scottySocket Options
opts Socket
sock = forall (m :: * -> *) (n :: * -> *).
(Monad m, MonadIO n) =>
Options
-> Socket -> (m Response -> IO Response) -> ScottyT m () -> n ()
Trans.scottySocketT Options
opts Socket
sock forall a. a -> a
id
scottyApp :: ScottyM () -> IO Application
scottyApp :: ScottyM () -> IO Application
scottyApp = forall (m :: * -> *) (n :: * -> *).
(Monad m, Monad n) =>
(m Response -> IO Response) -> ScottyT m () -> n Application
Trans.scottyAppT forall a. a -> a
id
defaultHandler :: ErrorHandler IO -> ScottyM ()
defaultHandler :: ErrorHandler IO -> ScottyM ()
defaultHandler = forall (m :: * -> *). Monad m => ErrorHandler m -> ScottyT m ()
Trans.defaultHandler
middleware :: Middleware -> ScottyM ()
middleware :: Middleware -> ScottyM ()
middleware = forall (m :: * -> *). Middleware -> ScottyT m ()
Trans.middleware
nested :: Application -> ActionM ()
nested :: Application -> ActionM ()
nested = forall (m :: * -> *). MonadIO m => Application -> ActionT m ()
Trans.nested
setMaxRequestBodySize :: Kilobytes -> ScottyM ()
setMaxRequestBodySize :: Port -> ScottyM ()
setMaxRequestBodySize = forall (m :: * -> *). Port -> ScottyT m ()
Trans.setMaxRequestBodySize
raise :: Text -> ActionM a
raise :: forall a. Text -> ActionM a
raise = forall (m :: * -> *) a. MonadIO m => Text -> ActionT m a
Trans.raise
raiseStatus :: Status -> Text -> ActionM a
raiseStatus :: forall a. Status -> Text -> ActionM a
raiseStatus = 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 = forall (m :: * -> *) e a.
(MonadIO m, Exception e) =>
e -> ActionT m a
Trans.throw
next :: ActionM ()
next :: ActionM ()
next = forall (m :: * -> *) a. Monad m => ActionT m a
Trans.next
finish :: ActionM a
finish :: forall a. ActionM a
finish = 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 = 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 = forall (m :: * -> *) a. MonadIO m => IO a -> ActionT m a
Trans.liftAndCatchIO
redirect :: Text -> ActionM a
redirect :: forall a. Text -> ActionM a
redirect = forall (m :: * -> *) a. Monad m => Text -> ActionT m a
Trans.redirect
request :: ActionM Request
request :: ActionM Request
request = forall (m :: * -> *). Monad m => ActionT m Request
Trans.request
files :: ActionM [File]
files :: ActionM [File]
files = forall (m :: * -> *). Monad m => ActionT m [File]
Trans.files
header :: Text -> ActionM (Maybe Text)
= forall (m :: * -> *). Monad m => Text -> ActionT m (Maybe Text)
Trans.header
headers :: ActionM [(Text, Text)]
= forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.headers
body :: ActionM ByteString
body :: ActionM ByteString
body = forall (m :: * -> *). MonadIO m => ActionT m ByteString
Trans.body
bodyReader :: ActionM (IO BS.ByteString)
bodyReader :: ActionM (IO ByteString)
bodyReader = forall (m :: * -> *). Monad m => ActionT m (IO ByteString)
Trans.bodyReader
jsonData :: FromJSON a => ActionM a
jsonData :: forall a. FromJSON a => ActionM a
jsonData = 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 = 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 = 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 = 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 = forall a (m :: * -> *).
(Parsable a, Monad m) =>
Text -> ActionT m a
Trans.queryParam
params :: ActionM [Param]
params :: ActionM [(Text, Text)]
params = 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 = forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.captureParams
formParams :: ActionM [Param]
formParams :: ActionM [(Text, Text)]
formParams = forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.formParams
queryParams :: ActionM [Param]
queryParams :: ActionM [(Text, Text)]
queryParams = forall (m :: * -> *). Monad m => ActionT m [(Text, Text)]
Trans.queryParams
status :: Status -> ActionM ()
status :: Status -> ActionM ()
status = forall (m :: * -> *). MonadIO m => Status -> ActionT m ()
Trans.status
addHeader :: Text -> Text -> ActionM ()
= forall (m :: * -> *). MonadIO m => Text -> Text -> ActionT m ()
Trans.addHeader
setHeader :: Text -> Text -> ActionM ()
= forall (m :: * -> *). MonadIO m => Text -> Text -> ActionT m ()
Trans.setHeader
text :: Text -> ActionM ()
text :: Text -> ActionM ()
text = forall (m :: * -> *). MonadIO m => Text -> ActionT m ()
Trans.text
html :: Text -> ActionM ()
html :: Text -> ActionM ()
html = forall (m :: * -> *). MonadIO m => Text -> ActionT m ()
Trans.html
file :: FilePath -> ActionM ()
file :: FilePath -> ActionM ()
file = forall (m :: * -> *). MonadIO m => FilePath -> ActionT m ()
Trans.file
json :: ToJSON a => a -> ActionM ()
json :: forall a. ToJSON a => a -> ActionM ()
json = forall a (m :: * -> *). (ToJSON a, MonadIO m) => a -> ActionT m ()
Trans.json
stream :: StreamingBody -> ActionM ()
stream :: StreamingBody -> ActionM ()
stream = forall (m :: * -> *). MonadIO m => StreamingBody -> ActionT m ()
Trans.stream
raw :: ByteString -> ActionM ()
raw :: ByteString -> ActionM ()
raw = forall (m :: * -> *). MonadIO m => ByteString -> ActionT m ()
Trans.raw
get :: RoutePattern -> ActionM () -> ScottyM ()
get :: RoutePattern -> ActionM () -> ScottyM ()
get = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.get
post :: RoutePattern -> ActionM () -> ScottyM ()
post :: RoutePattern -> ActionM () -> ScottyM ()
post = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.post
put :: RoutePattern -> ActionM () -> ScottyM ()
put :: RoutePattern -> ActionM () -> ScottyM ()
put = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.put
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.delete
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.patch
options :: RoutePattern -> ActionM () -> ScottyM ()
options :: RoutePattern -> ActionM () -> ScottyM ()
options = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.options
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny = forall (m :: * -> *).
MonadUnliftIO m =>
RoutePattern -> ActionT m () -> ScottyT m ()
Trans.matchAny
notFound :: ActionM () -> ScottyM ()
notFound :: ActionM () -> ScottyM ()
notFound = forall (m :: * -> *).
MonadUnliftIO m =>
ActionT m () -> ScottyT m ()
Trans.notFound
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute = 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