-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple web framework inspired by scotty. -- -- Simple web framework inspired by scotty. -- --
-- {-# LANGUAGE QuasiQuotes #-}
-- {-# LANGUAGE OverloadedStrings #-}
--
-- import Web.Apiary
-- import Network.Wai.Handler.Warp
-- import qualified Data.ByteString.Lazy.Char8 as L
--
-- main :: IO ()
-- main = run 3000 . runApiary def $ do
-- [capture|/:Int|] . ("name" =: pLazyByteString) . stdMethod GET . action $ \age name -> do
-- guard (age >= 18)
-- contentType "text/html"
-- lbs . L.concat $ ["<h1>Hello, ", name, "!</h1>\n"]
--
--
-- -- $ curl localhost:3000 -- 404 Page Notfound. -- $ curl 'localhost:3000/20?name=arice' -- <h1>Hello, arice!</h1> -- $ curl 'localhost:3000/15?name=bob' -- 404 Page Notfound. -- $ curl -XPOST 'localhost:3000/20?name=arice' -- 404 Page Notfound. ---- --
-- producer :: Monad m => Producer (Flush Builder) IO () -> ActionT m () -- producer = response (s h -> responseProducer s h) --response :: Monad m => (Status -> ResponseHeaders -> Response) -> ActionT m () -- | redirect with: -- -- 303 See Other (HTTP/1.1) or 302 Moved Temporarily (Other) -- -- since 0.6.2.0. redirect :: Monad m => ByteString -> ActionT m () -- | redirect with 301 Moved Permanently. since 0.3.3.0. redirectPermanently :: Monad m => ByteString -> ActionT m () -- | redirect with: -- -- 307 Temporary Redirect (HTTP/1.1) or 302 Moved Temporarily (Other) -- -- since 0.3.3.0. redirectTemporary :: Monad m => ByteString -> ActionT m () -- | redirect handler -- -- set status and add location header. since 0.3.3.0. -- -- rename from redirect in 0.6.2.0. redirectWith :: Monad m => Status -> ByteString -> ActionT m () -- | redirect with 302 Found. since 0.3.3.0. -- | Deprecated: use redirect redirectFound :: Monad m => ByteString -> ActionT m () -- | redirect with 303 See Other. since 0.3.3.0. -- | Deprecated: use redirect redirectSeeOther :: Monad m => ByteString -> ActionT m () -- | Deprecated: use stream source :: Monad m => StreamingBody -> ActionT m () module Control.Monad.Apiary.Filter.Internal -- | low level filter function. function :: (Functor n, Monad n) => (SList c -> Request -> Maybe (SList c')) -> ApiaryT c' n m b -> ApiaryT c n m b -- | filter and append argument. function' :: (Functor n, Monad n) => (Request -> Maybe a) -> ApiaryT (Snoc as a) n m b -> ApiaryT as n m b -- | filter only(not modify arguments). function_ :: (Functor n, Monad n) => (Request -> Bool) -> ApiaryT c n m b -> ApiaryT c n m b -- | filter by action. since 0.6.1.0. focus :: (Functor n, Monad n) => (SList c -> ActionT n (SList c')) -> ApiaryT c' n m a -> ApiaryT c n m a module Control.Monad.Apiary -- | most generic Apiary monad. since 0.8.0.0. data ApiaryT c n m a -- | no transformer. (ActionT IO, ApiaryT Identity) type Apiary c = ApiaryT c IO Identity runApiary :: ApiaryConfig -> Apiary '[] a -> Application runApiaryT :: (Monad n, Monad m) => (forall b. n b -> IO b) -> ApiaryConfig -> ApiaryT '[] n m a -> m Application apiaryConfig :: (Functor n, Monad n) => ApiaryT c n m ApiaryConfig -- | splice ActionT ApiaryT. action :: (Functor n, Monad n) => Fn c (ActionT n ()) -> ApiaryT c n m () -- | like action. but not apply arguments. since 0.8.0.0. action' :: (Functor n, Monad n) => (SList c -> ActionT n ()) -> ApiaryT c n m () -- | execute action before main action. since v0.4.2.0 -- | Deprecated: use action' actionWithPreAction :: (Functor n, Monad n) => (SList xs -> ActionT n a) -> Fn xs (ActionT n ()) -> ApiaryT xs n m () module Control.Monad.Apiary.Filter.Internal.Capture data Equal Equal :: Text -> Equal type Fetch = Proxy class CaptureElem a where type family Next a (xs :: [*]) :: [*] captureElem :: CaptureElem a => a -> Text -> SList xs -> Maybe (SList (Next a xs)) type Capture as = All CaptureElem as capture' :: Capture as => SList as -> [Text] -> SList xs -> Maybe (SList (CaptureResult xs as)) -- | low level (without Template Haskell) capture. since 0.4.2.0 -- --
-- myCapture :: SList '[Equal, Fetch Int, Fetch String] -- myCapture = Equal "path" ::: pInt ::: pString ::: SNil -- -- capture myCapture . stdMethod GET . action $ age name -> do -- yourAction --capture :: (Functor n, Monad n) => Capture as => SList as -> ApiaryT (CaptureResult xs as) n m b -> ApiaryT xs n m b instance Path a => CaptureElem (Fetch a) instance CaptureElem Equal module Control.Monad.Apiary.Filter -- | filter by HTTP method. since 0.1.0.0. method :: (Functor n, Monad n) => Method -> ApiaryT c n m a -> ApiaryT c n m a -- | filter by HTTP method using StdMethod. since 0.1.0.0. stdMethod :: (Functor n, Monad n) => StdMethod -> ApiaryT c n m a -> ApiaryT c n m a -- | http version filter. since 0.5.0.0. httpVersion :: (Functor n, Monad n) => HttpVersion -> ApiaryT c n m b -> ApiaryT c n m b -- | http/0.9 only accepted fiter. since 0.5.0.0. http09 :: (Functor n, Monad n) => ApiaryT c n m b -> ApiaryT c n m b -- | http/1.0 only accepted fiter. since 0.5.0.0. http10 :: (Functor n, Monad n) => ApiaryT c n m b -> ApiaryT c n m b -- | http/1.1 only accepted fiter. since 0.5.0.0. http11 :: (Functor n, Monad n) => ApiaryT c n m b -> ApiaryT c n m b -- | filter by rootPattern of ApiaryConfig. root :: (Functor n, Monad n) => ApiaryT c n m b -> ApiaryT c n m b -- | capture QuasiQuoter. since 0.1.0.0. -- -- example: -- --
-- [capture|/path|] -- first path == path -- [capture|/int/:Int|] -- first path == int && get 2nd path as Int. -- [capture|/:Int/:Double|] -- get first path as Int and get 2nd path as Double. --capture :: QuasiQuoter -- | low level query getter. since 0.5.0.0. -- --
-- query key (Proxy :: Proxy (fetcher type)) ---- -- examples: -- --
-- query key (Proxy :: Proxy (First Int)) -- get first 'key' query parameter as Int. -- query key (Proxy :: Proxy (Option (Maybe Int)) -- get first 'key' query parameter as Int. allow without param or value. -- query key (Proxy :: Proxy (Many String) -- get all 'key' query parameter as String. --query :: (ReqParam a, Strategy w, Functor n, MonadIO n) => ByteString -> Proxy (w a) -> ApiaryT (SNext w as a) n m b -> ApiaryT as n m b -- | get first matched paramerer. since 0.5.0.0. -- --
-- key =: pInt == query key (pFirst pInt) == query key (Proxy :: Proxy (First Int)) --(=:) :: (Functor n, MonadIO n, ReqParam a) => ByteString -> Proxy a -> ApiaryT (Snoc as a) n m b -> ApiaryT as n m b -- | get one matched paramerer. since 0.5.0.0. -- -- when more one parameger given, not matched. -- --
-- key =: pInt == query key (pOne pInt) == query key (Proxy :: Proxy (One Int)) --(=!:) :: (Functor n, MonadIO n, ReqParam a) => ByteString -> Proxy a -> ApiaryT (Snoc as a) n m b -> ApiaryT as n m b -- | get optional first paramerer. since 0.5.0.0. -- -- when illegal type parameter given, fail mather(don't give Nothing). -- --
-- key =: pInt == query key (pOption pInt) == query key (Proxy :: Proxy (Option Int)) --(=?:) :: (Functor n, MonadIO n, ReqParam a) => ByteString -> Proxy a -> ApiaryT (Snoc as (Maybe a)) n m b -> ApiaryT as n m b -- | check parameger given and type. since 0.5.0.0. -- -- If you wan't to allow any type, give pVoid. -- --
-- key =: pInt == query key (pCheck pInt) == query key (Proxy :: Proxy (Check Int)) --(?:) :: (Functor n, MonadIO n, ReqParam a) => ByteString -> Proxy a -> ApiaryT as n m b -> ApiaryT as n m b -- | get many paramerer. since 0.5.0.0. -- --
-- key =: pInt == query key (pMany pInt) == query key (Proxy :: Proxy (Many Int)) --(=*:) :: (Functor n, MonadIO n, ReqParam a) => ByteString -> Proxy a -> ApiaryT (Snoc as [a]) n m b -> ApiaryT as n m b -- | get some paramerer. since 0.5.0.0. -- --
-- key =: pInt == query key (pSome pInt) == query key (Proxy :: Proxy (Some Int)) --(=+:) :: (Functor n, MonadIO n, ReqParam a) => ByteString -> Proxy a -> ApiaryT (Snoc as [a]) n m b -> ApiaryT as n m b -- | query exists checker. -- --
-- hasQuery q = query q (Proxy :: Proxy (Check ())) --hasQuery :: (Functor n, MonadIO n) => ByteString -> ApiaryT c n m a -> ApiaryT c n m a -- | check whether to exists specified header or not. since 0.6.0.0. hasHeader :: (Functor n, Monad n) => HeaderName -> ApiaryT as n m b -> ApiaryT as n m b -- | check whether to exists specified valued header or not. since 0.6.0.0. eqHeader :: (Functor n, Monad n) => HeaderName -> ByteString -> ApiaryT as n m b -> ApiaryT as n m b -- | filter by headers up to 100 entries. since 0.6.0.0. headers :: (Functor n, Monad n) => HeaderName -> ApiaryT (Snoc as [ByteString]) n m b -> ApiaryT as n m b -- | filter by header and get first. since 0.6.0.0. header :: (Functor n, Monad n) => HeaderName -> ApiaryT (Snoc as ByteString) n m b -> ApiaryT as n m b -- | low level header filter. since 0.6.0.0. header' :: (Strategy w, Functor n, Monad n) => (forall x. Proxy x -> Proxy (w x)) -> (Header -> Bool) -> ApiaryT (SNext w as ByteString) n m b -> ApiaryT as n m b -- | filter by ssl accessed. since 0.1.0.0. ssl :: (Functor n, Monad n) => ApiaryT c n m a -> ApiaryT c n m a module Web.Apiary -- | shortcut action. since 0.6.0.0. -- --
-- [act|200 .html|] == [act|200 text/html|] == -- action $ \arguments -> do -- status 200 -- contentType text/html --act :: QuasiQuoter