{-# LANGUAGE OverloadedStrings, RankNTypes #-}
module Web.Scotty
(
scotty, scottyApp, scottyOpts, scottySocket, Options(..)
, middleware, get, post, put, delete, patch, options, addroute, matchAny, notFound, setMaxRequestBodySize
, capture, regex, function, literal
, request, header, headers, body, bodyReader, param, params, jsonData, files
, status, addHeader, setHeader, redirect
, text, html, file, json, stream, raw
, raise, raiseStatus, rescue, next, finish, defaultHandler, liftAndCatchIO
, Param, Trans.Parsable(..), Trans.readEither
, ScottyM, ActionM, RoutePattern, File, Kilobytes
) where
import qualified Web.Scotty.Trans as Trans
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, Param, RoutePattern, Options, File, Kilobytes)
type ScottyM = ScottyT Text IO
type ActionM = ActionT Text IO
scotty :: Port -> ScottyM () -> IO ()
scotty :: Port -> ScottyM () -> IO ()
scotty Port
p = Port -> (IO Response -> IO Response) -> ScottyM () -> IO ()
forall (m :: * -> *) (n :: * -> *) e.
(Monad m, MonadIO n) =>
Port -> (m Response -> IO Response) -> ScottyT e 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 :: * -> *) e.
(Monad m, MonadIO n) =>
Options -> (m Response -> IO Response) -> ScottyT e 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 :: * -> *) e.
(Monad m, MonadIO n) =>
Options
-> Socket -> (m Response -> IO Response) -> ScottyT e 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 :: * -> *) e.
(Monad m, Monad n) =>
(m Response -> IO Response) -> ScottyT e m () -> n Application
Trans.scottyAppT IO Response -> IO Response
forall a. a -> a
id
defaultHandler :: (Text -> ActionM ()) -> ScottyM ()
defaultHandler :: (Text -> ActionM ()) -> ScottyM ()
defaultHandler = (Text -> ActionM ()) -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
(e -> ActionT e m ()) -> ScottyT e m ()
Trans.defaultHandler
middleware :: Middleware -> ScottyM ()
middleware :: Middleware -> ScottyM ()
middleware = Middleware -> ScottyM ()
forall e (m :: * -> *). Middleware -> ScottyT e m ()
Trans.middleware
setMaxRequestBodySize :: Kilobytes -> ScottyM ()
setMaxRequestBodySize :: Port -> ScottyM ()
setMaxRequestBodySize = Port -> ScottyM ()
forall e (m :: * -> *). Port -> ScottyT e m ()
Trans.setMaxRequestBodySize
raise :: Text -> ActionM a
raise :: forall a. Text -> ActionM a
raise = Text -> ActionT Text IO a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
e -> ActionT e m a
Trans.raise
raiseStatus :: Status -> Text -> ActionM a
raiseStatus :: forall a. Status -> Text -> ActionM a
raiseStatus = Status -> Text -> ActionT Text IO a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
Status -> e -> ActionT e m a
Trans.raiseStatus
next :: ActionM a
next :: forall a. ActionM a
next = ActionT Text IO a
forall e (m :: * -> *) a. (ScottyError e, Monad m) => ActionT e m a
Trans.next
finish :: ActionM a
finish :: forall a. ActionM a
finish = ActionT Text IO a
forall e (m :: * -> *) a. (ScottyError e, Monad m) => ActionT e m a
Trans.finish
rescue :: ActionM a -> (Text -> ActionM a) -> ActionM a
rescue :: forall a. ActionM a -> (Text -> ActionM a) -> ActionM a
rescue = ActionT Text IO a
-> (Text -> ActionT Text IO a) -> ActionT Text IO a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
Trans.rescue
liftAndCatchIO :: IO a -> ActionM a
liftAndCatchIO :: forall a. IO a -> ActionM a
liftAndCatchIO = IO a -> ActionT Text IO a
forall e (m :: * -> *) a.
(ScottyError e, MonadIO m) =>
IO a -> ActionT e m a
Trans.liftAndCatchIO
redirect :: Text -> ActionM a
redirect :: forall a. Text -> ActionM a
redirect = Text -> ActionT Text IO a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
Text -> ActionT e m a
Trans.redirect
request :: ActionM Request
request :: ActionM Request
request = ActionM Request
forall (m :: * -> *) e. Monad m => ActionT e m Request
Trans.request
files :: ActionM [File]
files :: ActionM [File]
files = ActionM [File]
forall (m :: * -> *) e. Monad m => ActionT e m [File]
Trans.files
header :: Text -> ActionM (Maybe Text)
= Text -> ActionM (Maybe Text)
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m (Maybe Text)
Trans.header
headers :: ActionM [(Text, Text)]
= ActionM [(Text, Text)]
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
ActionT e m [(Text, Text)]
Trans.headers
body :: ActionM ByteString
body :: ActionM ByteString
body = ActionM ByteString
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
ActionT e m ByteString
Trans.body
bodyReader :: ActionM (IO BS.ByteString)
bodyReader :: ActionM (IO ByteString)
bodyReader = ActionM (IO ByteString)
forall (m :: * -> *) e. Monad m => ActionT e m (IO ByteString)
Trans.bodyReader
jsonData :: FromJSON a => ActionM a
jsonData :: forall a. FromJSON a => ActionM a
jsonData = ActionT Text IO a
forall a e (m :: * -> *).
(FromJSON a, ScottyError e, MonadIO m) =>
ActionT e m a
Trans.jsonData
param :: Trans.Parsable a => Text -> ActionM a
param :: forall a. Parsable a => Text -> ActionM a
param = Text -> ActionT Text IO a
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
Trans.param
params :: ActionM [Param]
params :: ActionM [(Text, Text)]
params = ActionM [(Text, Text)]
forall (m :: * -> *) e. Monad m => ActionT e m [(Text, Text)]
Trans.params
status :: Status -> ActionM ()
status :: Status -> ActionM ()
status = Status -> ActionM ()
forall (m :: * -> *) e. Monad m => Status -> ActionT e m ()
Trans.status
addHeader :: Text -> Text -> ActionM ()
= Text -> Text -> ActionM ()
forall (m :: * -> *) e. Monad m => Text -> Text -> ActionT e m ()
Trans.addHeader
setHeader :: Text -> Text -> ActionM ()
= Text -> Text -> ActionM ()
forall (m :: * -> *) e. Monad m => Text -> Text -> ActionT e m ()
Trans.setHeader
text :: Text -> ActionM ()
text :: Text -> ActionM ()
text = Text -> ActionM ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m ()
Trans.text
html :: Text -> ActionM ()
html :: Text -> ActionM ()
html = Text -> ActionM ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m ()
Trans.html
file :: FilePath -> ActionM ()
file :: FilePath -> ActionM ()
file = FilePath -> ActionM ()
forall (m :: * -> *) e. Monad m => FilePath -> ActionT e m ()
Trans.file
json :: ToJSON a => a -> ActionM ()
json :: forall a. ToJSON a => a -> ActionM ()
json = a -> ActionM ()
forall a e (m :: * -> *).
(ToJSON a, ScottyError e, Monad m) =>
a -> ActionT e m ()
Trans.json
stream :: StreamingBody -> ActionM ()
stream :: StreamingBody -> ActionM ()
stream = StreamingBody -> ActionM ()
forall (m :: * -> *) e. Monad m => StreamingBody -> ActionT e m ()
Trans.stream
raw :: ByteString -> ActionM ()
raw :: ByteString -> ActionM ()
raw = ByteString -> ActionM ()
forall (m :: * -> *) e. Monad m => ByteString -> ActionT e m ()
Trans.raw
get :: RoutePattern -> ActionM () -> ScottyM ()
get :: RoutePattern -> ActionM () -> ScottyM ()
get = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.get
post :: RoutePattern -> ActionM () -> ScottyM ()
post :: RoutePattern -> ActionM () -> ScottyM ()
post = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.post
put :: RoutePattern -> ActionM () -> ScottyM ()
put :: RoutePattern -> ActionM () -> ScottyM ()
put = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.put
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete :: RoutePattern -> ActionM () -> ScottyM ()
delete = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.delete
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch :: RoutePattern -> ActionM () -> ScottyM ()
patch = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.patch
options :: RoutePattern -> ActionM () -> ScottyM ()
options :: RoutePattern -> ActionM () -> ScottyM ()
options = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.options
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny :: RoutePattern -> ActionM () -> ScottyM ()
matchAny = RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
Trans.matchAny
notFound :: ActionM () -> ScottyM ()
notFound :: ActionM () -> ScottyM ()
notFound = ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
ActionT e m () -> ScottyT e m ()
Trans.notFound
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute = StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
StdMethod -> RoutePattern -> ActionT e m () -> ScottyT e 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