-- 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.
--   
-- -- -- -- full example & tutorial: -- https://github.com/philopon/apiary/blob/master/examples/main.lhs @package apiary @version 0.5.0.0 module Data.Apiary.SList data SList (as :: [*]) SNil :: SList '[] (:::) :: a -> SList xs -> SList (a : xs) apply :: Fn xs r -> SList xs -> r sSnoc :: SList as -> a -> SList (Snoc as a) type Reverse (a :: [*]) = Rev a '[] sReverse :: SList as -> SList (Reverse as) instance (All Show as) => Show (SList as) module Control.Monad.Apiary.Filter.Internal -- | raw and most generic filter function. function :: Monad m => (SList c -> Request -> Maybe (SList c')) -> ApiaryT c' m b -> ApiaryT c m b -- | filter and append argument. function' :: Monad m => (Request -> Maybe a) -> ApiaryT (Snoc as a) m b -> ApiaryT as m b -- | filter only(not modify arguments). function_ :: Monad m => (Request -> Bool) -> ApiaryT c m b -> ApiaryT c m b module Data.Apiary.Param class Path a readPath :: Path a => Text -> Maybe a class Query a readQuery :: Query a => Maybe ByteString -> Maybe a pInt :: Proxy Int pInt8 :: Proxy Int8 pInt16 :: Proxy Int16 pInt32 :: Proxy Int32 pInt64 :: Proxy Int64 pInteger :: Proxy Integer pWord :: Proxy Word pWord8 :: Proxy Word8 pWord32 :: Proxy Word32 pWord64 :: Proxy Word64 pDouble :: Proxy Double pFloat :: Proxy Float pText :: Proxy Text pLazyText :: Proxy Text pByteString :: Proxy ByteString pLazyByteString :: Proxy ByteString pString :: Proxy String pVoid :: Proxy () pMaybe :: Proxy a -> Proxy (Maybe a) instance Query () instance Query a => Query (Maybe a) instance Query String instance Query ByteString instance Query ByteString instance Query Text instance Query Text instance Query Float instance Query Double instance Query Word64 instance Query Word32 instance Query Word16 instance Query Word8 instance Query Word instance Query Integer instance Query Int64 instance Query Int32 instance Query Int16 instance Query Int8 instance Query Int instance Path String instance Path ByteString instance Path ByteString instance Path Text instance Path Text instance Path Float instance Path Double instance Path Word64 instance Path Word32 instance Path Word16 instance Path Word8 instance Path Word instance Path Integer instance Path Int64 instance Path Int32 instance Path Int16 instance Path Int8 instance Path Int instance Path Char module Control.Monad.Apiary.Action data ActionT m a data ApiaryConfig ApiaryConfig :: Application -> Status -> ResponseHeaders -> [ByteString] -> (FilePath -> ByteString) -> ApiaryConfig -- | call when no handler matched. notFound :: ApiaryConfig -> Application -- | used unless call status function. defaultStatus :: ApiaryConfig -> Status -- | initial headers. defaultHeader :: ApiaryConfig -> ResponseHeaders -- | used by root filter. rootPattern :: ApiaryConfig -> [ByteString] mimeType :: ApiaryConfig -> FilePath -> ByteString -- | stop handler and send current state. since 0.3.3.0. stop :: Monad m => ActionT m a -- | stop with response. since 0.4.2.0. stopWith :: Monad m => Response -> ActionT m a getRequest :: Monad m => ActionT m Request -- | Deprecated: use qeury derived filter. getQuery :: Monad m => ByteString -> ActionT m (Maybe (Maybe ByteString)) -- | when query parameter is not found, mzero(pass next handler). -- | Deprecated: use qeury derived filter. getQuery' :: Monad m => ByteString -> ActionT m (Maybe ByteString) getRequestHeader :: Monad m => HeaderName -> ActionT m (Maybe ByteString) -- | when request header is not found, mzero(pass next handler). getRequestHeader' :: Monad m => HeaderName -> ActionT m ByteString status :: Monad m => Status -> ActionT m () addHeader :: Monad m => HeaderName -> ByteString -> ActionT m () setHeaders :: Monad m => ResponseHeaders -> ActionT m () modifyHeader :: Monad m => (ResponseHeaders -> ResponseHeaders) -> ActionT m () contentType :: Monad m => ByteString -> ActionT m () -- | set body to file content and detect Content-Type by extension. file :: Monad m => FilePath -> Maybe FilePart -> ActionT m () file' :: Monad m => FilePath -> Maybe FilePart -> ActionT m () builder :: Monad m => Builder -> ActionT m () lbs :: Monad m => ByteString -> ActionT m () source :: Monad m => Source IO (Flush Builder) -> ActionT m () -- | redirect handler -- -- set status, location header and stop. since 0.3.3.0. redirect :: Monad m => Status -> ByteString -> ActionT m a -- | redirect with 301 Moved Permanently. since 0.3.3.0. redirectPermanently :: Monad m => ByteString -> ActionT m a -- | redirect with 302 Found. since 0.3.3.0. redirectFound :: Monad m => ByteString -> ActionT m a -- | redirect with 303 See Other. since 0.3.3.0. redirectSeeOther :: Monad m => ByteString -> ActionT m a -- | redirect with 307 Temporary Redirect. since 0.3.3.0. redirectTemporary :: Monad m => ByteString -> ActionT m a module Control.Monad.Apiary data ApiaryT c m a type Apiary c = ApiaryT c IO runApiary :: ApiaryConfig -> Apiary '[] a -> Application runApiaryT :: Monad m => ApiaryConfig -> (forall x. m x -> IO x) -> ApiaryT '[] m a -> Application apiaryConfig :: ApiaryT c m ApiaryConfig action :: Monad m => Fn c (ActionT m ()) -> ApiaryT c m () -- | Deprecated: use action method. action_ :: Monad m => ActionT m () -> ApiaryT c m () -- | execute action before main action. since v0.4.2.0 actionWithPreAction :: Monad m => (SList xs -> ActionT IO a) -> Fn xs (ActionT m ()) -> ApiaryT xs m () module Control.Monad.Apiary.Filter.Internal.Query -- | 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 :: (Query a, Strategy w, Monad m) => ByteString -> Proxy (w a) -> ApiaryT (SNext w as a) m b -> ApiaryT as m b class Strategy (w :: * -> *) where type family SNext w (as :: [*]) a :: [*] readStrategy :: (Strategy w, Query a) => ByteString -> Proxy (w a) -> Query -> SList as -> Maybe (SList (SNext w as a)) getQuery :: Query a => Proxy (w a) -> ByteString -> Query -> [Maybe a] -- | get first matched key( [1,) params to Type.). since 0.5.0.0. data Option a -- | get first matched key ( [0,) params to Maybe Type.) since 0.5.0.0. data First a -- | get key ( [1] param to Type.) since 0.5.0.0. data One a -- | get parameters ( [0,) params to [Type] ) since 0.5.0.0. data Many a -- | get parameters ( [1,) params to [Type] ) since 0.5.0.0. data Some a -- | type check ( [0,) params to No argument ) since 0.5.0.0. data Check a instance Strategy Check instance Strategy Some instance Strategy Many instance Strategy One instance Strategy First instance Strategy Option 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 :: (Capture as, Monad m) => SList as -> ApiaryT (CaptureResult xs as) m b -> ApiaryT xs m b instance Path a => CaptureElem (Fetch a) instance CaptureElem Equal module Control.Monad.Apiary.Filter method :: Monad m => Method -> ApiaryT c m a -> ApiaryT c m a stdMethod :: Monad m => StdMethod -> ApiaryT c m a -> ApiaryT c m a -- | http version filter. since 0.5.0.0. httpVersion :: Monad m => HttpVersion -> ApiaryT c m b -> ApiaryT c m b -- | http/0.9 only accepted fiter. since 0.5.0.0. http09 :: Monad m => ApiaryT c m b -> ApiaryT c m b -- | http/1.0 only accepted fiter. since 0.5.0.0. http10 :: Monad m => ApiaryT c m b -> ApiaryT c m b -- | http/1.1 only accepted fiter. since 0.5.0.0. http11 :: Monad m => ApiaryT c m b -> ApiaryT c m b -- | filter by rootPattern of ApiaryConfig. root :: Monad m => ApiaryT c m b -> ApiaryT c m b capture :: QuasiQuoter -- | get first matched paramerer. since 0.5.0.0. -- --
--   key =: pInt == query key (Proxy :: Proxy (First Int))
--   
(=:) :: (Query a, Monad m) => ByteString -> Proxy a -> ApiaryT (Snoc as a) m b -> ApiaryT as m b -- | get one matched paramerer. since 0.5.0.0. -- -- when more one parameger given, not matched. -- --
--   key =: pInt == query key (Proxy :: Proxy (One Int))
--   
(=!:) :: (Query a, Monad m) => ByteString -> Proxy a -> ApiaryT (Snoc as a) m b -> ApiaryT as 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 (Proxy :: Proxy (Option Int))
--   
(=?:) :: (Query a, Monad m) => ByteString -> Proxy a -> ApiaryT (Snoc as (Maybe a)) m b -> ApiaryT as 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 (Proxy :: Proxy (Check Int))
--   
(?:) :: (Query a, Monad m) => ByteString -> Proxy a -> ApiaryT as m b -> ApiaryT as m b -- | get many paramerer. since 0.5.0.0. -- --
--   key =: pInt == query key (Proxy :: Proxy (Many Int))
--   
(=*:) :: (Query a, Monad m) => ByteString -> Proxy a -> ApiaryT (Snoc as [a]) m b -> ApiaryT as m b -- | get some paramerer. since 0.5.0.0. -- --
--   key =: pInt == query key (Proxy :: Proxy (Some Int))
--   
(=+:) :: (Query a, Monad m) => ByteString -> Proxy a -> ApiaryT (Snoc as [a]) m b -> ApiaryT as m b -- | query exists checker. -- --
--   hasQuery q = query q (Proxy :: Proxy (Check ()))
--   
hasQuery :: Monad m => ByteString -> ApiaryT c m a -> ApiaryT c m a ssl :: Monad m => ApiaryT c m a -> ApiaryT c m a -- | filter by query parameter. since 0.4.0.0. -- | Deprecated: use query related filters queryAll :: Monad m => ByteString -> ApiaryT (Snoc as [Maybe ByteString]) m b -> ApiaryT as m b -- | filter by query parameter. since 0.4.0.0. -- | Deprecated: use query related filters queryAll' :: Monad m => ByteString -> ApiaryT (Snoc as [ByteString]) m b -> ApiaryT as m b -- | filter [1,) parameters by query parameter allows empty value. since -- 0.4.3.0. -- | Deprecated: use query related filters querySome :: Monad m => ByteString -> ApiaryT (Snoc as [Maybe ByteString]) m b -> ApiaryT as m b -- | filter [1,) parameters by query parameter not allows empty value. -- since 0.4.3.0. -- | Deprecated: use query related filters querySome' :: Monad m => ByteString -> ApiaryT (Snoc as [ByteString]) m b -> ApiaryT as m b -- | filter by query parameter. allow empty value. since 0.4.0.0. -- | Deprecated: use query related filters queryFirst :: Monad m => ByteString -> ApiaryT (Snoc as (Maybe ByteString)) m b -> ApiaryT as m b -- | filter by query parameter. not allow empty value. since 0.4.0.0. -- | Deprecated: use query related filters queryFirst' :: Monad m => ByteString -> ApiaryT (Snoc as ByteString) m b -> ApiaryT as m b -- | get [0,) parameters by query parameter allows empty value. since -- 0.4.3.0. -- | Deprecated: use query related filters queryMany :: Monad m => ByteString -> ApiaryT (Snoc as [Maybe ByteString]) m b -> ApiaryT as m b -- | get [0,) parameters by query parameter not allows empty value. since -- 0.4.3.0. -- | Deprecated: use query related filters queryMany' :: Monad m => ByteString -> ApiaryT (Snoc as [ByteString]) m b -> ApiaryT as m b -- | get first query parameter allow empty value. since 0.4.3.0, -- | Deprecated: use query related filters maybeQueryFirst :: Monad m => ByteString -> ApiaryT (Snoc as (Maybe (Maybe ByteString))) m b -> ApiaryT as m b -- | get first query parameter not allow empty value. since 0.4.3.0, -- | Deprecated: use query related filters maybeQueryFirst' :: Monad m => ByteString -> ApiaryT (Snoc as (Maybe ByteString)) m b -> ApiaryT as m b module Web.Apiary