-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple and type safe web framework that generate web API documentation. -- -- Simple and type safe web framework that can be automatically generate -- API documentation. -- --
-- {-# LANGUAGE QuasiQuotes #-}
-- {-# LANGUAGE OverloadedStrings #-}
--
-- import Web.Apiary
-- import Network.Wai.Handler.Warp
-- import qualified Data.ByteString.Lazy.Char8 as L
--
-- main :: IO ()
-- main = runApiary (run 3000) def $ do
-- [capture|/age::Int|] . ([key|name|] =: pLazyByteString) . method GET . action $ do
-- (age, name) <- [params|age,name|]
-- guard (age >= 18)
-- contentType "text/html"
-- mapM_ appendLazyBytes ["<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. ---- --
-- param [key|foo|] --param :: (Member k v prms, Monad m) => proxy k -> ActionT exts prms m v -- | get parameters. since 1.0.0. -- --
-- [params|foo,bar|] == do { a <- param [key|foo|]; b <- param [key|bar|]; return (a, b) }
--
params :: QuasiQuoter
-- | set status code. since 0.1.0.0.
status :: Monad m => Status -> ActionT exts prms m ()
-- | add response header. since 0.1.0.0.
--
-- Don't set Content-Type using this function. Use contentType.
addHeader :: Monad m => HeaderName -> ByteString -> ActionT exts prms m ()
-- | set response headers. since 0.1.0.0.
--
-- Don't set Content-Type using this function. Use contentType.
setHeaders :: Monad m => ResponseHeaders -> ActionT exts prms m ()
-- | modify response header. since 0.1.0.0.
--
-- Don't set Content-Type using this function. Use contentType.
modifyHeader :: Monad m => (ResponseHeaders -> ResponseHeaders) -> ActionT exts prms m ()
-- | set content-type header.
--
-- if content-type header already exists, replace it. since 0.1.0.0.
contentType :: Monad m => ContentType -> ActionT exts prms m ()
-- | reset response body to no response. since v0.15.2.
reset :: Monad m => ActionT exts prms m ()
-- | set response body from builder. since 0.1.0.0.
builder :: Monad m => Builder -> ActionT exts prms m ()
-- | set response body from strict bytestring. since 0.15.2.
bytes :: Monad m => ByteString -> ActionT exts prms m ()
-- | set response body from lazy bytestring. since 0.15.2.
lazyBytes :: Monad m => ByteString -> ActionT exts prms m ()
-- | set response body from strict text. encoding UTF-8. since 0.15.2.
text :: Monad m => Text -> ActionT exts prms m ()
-- | set response body from lazy text. encoding UTF-8. since 0.15.2.
lazyText :: Monad m => Text -> ActionT exts prms m ()
-- | set response body from show. encoding UTF-8. since 0.15.2.
showing :: (Monad m, Show a) => a -> ActionT exts prms m ()
-- | set response body from ToJSON with content-type set to
-- application/json. since 2.0.2
json :: (Monad m, ToJSON a) => a -> ActionT exts prms m ()
-- | set response body from string. encoding UTF-8. since 0.15.2.
string :: Monad m => String -> ActionT exts prms m ()
-- | set response body from char. encoding UTF-8. since 0.15.2.
char :: Monad m => Char -> ActionT exts prms m ()
-- | append response body from builder. since 1.2.0.
appendBuilder :: Monad m => Builder -> ActionT exts prms m ()
-- | append response body from strict bytestring. since 1.2.0.
appendBytes :: Monad m => ByteString -> ActionT exts prms m ()
-- | append response body from lazy bytestring. since 1.2.0.
appendLazyBytes :: Monad m => ByteString -> ActionT exts prms m ()
-- | append response body from strict text. encoding UTF-8. since 1.2.0.
appendText :: Monad m => Text -> ActionT exts prms m ()
-- | append response body from lazy text. encoding UTF-8. since 1.2.0.
appendLazyText :: Monad m => Text -> ActionT exts prms m ()
-- | append response body from show. encoding UTF-8. since 1.2.0.
appendShowing :: (Monad m, Show a) => a -> ActionT exts prms m ()
-- | append response body from string. encoding UTF-8. since 1.2.0.
appendString :: Monad m => String -> ActionT exts prms m ()
-- | append response body from char. encoding UTF-8. since 1.2.0.
appendChar :: Monad m => Char -> ActionT exts prms m ()
-- | set response body file content and detect Content-Type by extension.
-- since 0.1.0.0.
--
-- file modification check since 0.17.2.
file :: MonadIO m => FilePath -> Maybe FilePart -> ActionT exts prms m ()
-- | set response body file content, without set Content-Type. since
-- 0.1.0.0.
file' :: MonadIO m => FilePath -> Maybe FilePart -> ActionT exts prms m ()
-- | redirect with:
--
-- 303 See Other (HTTP/1.1) or 302 Moved Temporarily (Other)
--
-- since 0.6.2.0.
redirect :: Monad m => ByteString -> ActionT exts prms m ()
-- | redirect with 301 Moved Permanently. since 0.3.3.0.
redirectPermanently :: Monad m => ByteString -> ActionT exts prms m ()
-- | redirect with:
--
-- 307 Temporary Redirect (HTTP/1.1) or 302 Moved Temporarily (Other)
--
-- since 0.3.3.0.
redirectTemporary :: Monad m => ByteString -> ActionT exts prms m ()
-- | auto generated document.
defaultDocumentationAction :: Monad m => DefaultDocumentConfig -> ActionT exts prms m ()
data DefaultDocumentConfig
DefaultDocumentConfig :: Text -> Maybe Html -> Bool -> Maybe Text -> DefaultDocumentConfig
[documentTitle] :: DefaultDocumentConfig -> Text
[documentDescription] :: DefaultDocumentConfig -> Maybe Html
[documentUseCDN] :: DefaultDocumentConfig -> Bool
-- | google analytics. since 0.17.0.
[documentGoogleAnalytics] :: DefaultDocumentConfig -> Maybe Text
type ContentType = ByteString
-- | stop with response. since 0.4.2.0.
stopWith :: Monad m => Response -> ActionT exts prms m a
applyDict :: Dict prms -> ActionT exts prms m a -> ActionT exts '[] m a
-- | get raw request. since 0.1.0.0.
getRequest :: Monad m => ActionT exts prms m Request
-- | get all request headers. since 0.6.0.0.
getHeaders :: Monad m => ActionT exts prms m RequestHeaders
getParams :: Monad m => ActionT exts prms m (Dict prms)
-- | only get parameters in query string.
getQueryParams :: Monad m => ActionT exts prms m Query
data ActionReqBody
-- | raw body
Unknown :: ByteString -> ActionReqBody
-- | url-encoded params
UrlEncoded :: [Param] -> ActionReqBody
-- | boundary params files
Multipart :: [Param] -> [File] -> ActionReqBody
-- | parse request body into ActionReqBody and return it. since
-- 1.2.2.
getReqBody :: MonadIO m => ActionT exts prms m ActionReqBody
-- | parse request body and return params. since 1.0.0.
getReqBodyParams :: MonadIO m => ActionT exts prms m [Param]
-- | parse request body and return files. since 0.9.0.0.
getReqBodyFiles :: MonadIO m => ActionT exts prms m [File]
-- | parse request body and try parse it as JSON.
--
-- it's recommended to use jsonReqBody filter to leverage type
-- level routing instead of getReqBodyJSON. since 2.0.0.
getReqBodyJSON :: (MonadIO m, FromJSON a) => ActionT exts prms m (Maybe a)
-- | send file contents as lazy bytestring response. since v1.1.4.
devFile :: MonadIO m => FilePath -> ActionT exts prms m ()
devFile' :: MonadIO m => FilePath -> ActionT exts prms m ()
-- | set response body source. since 0.9.0.0.
stream :: Monad m => StreamingBody -> ActionT exts prms m ()
-- | set raw response constructor. since 0.10.
--
-- example(use pipes-wai)
--
-- -- producer :: Monad m => Producer (Flush Builder) IO () -> ActionT' exts m () -- producer = response (s h -> responseProducer s h) --rawResponse :: Monad m => (Status -> ResponseHeaders -> Response) -> ActionT exts prms m () -- | Represents a streaming HTTP response body. It's a function of two -- parameters; the first parameter provides a means of sending another -- chunk of data, and the second parameter provides a means of flushing -- the data to the client. -- -- Since 3.0.0 type StreamingBody = (Builder -> IO ()) -> IO () -> IO () -- | lookup extensional state. since v1.2.0. lookupVault :: Key a -> ActionT exts prms m (Maybe a) -- | modify extensional state. since v1.2.0. modifyVault :: (Vault -> Vault) -> ActionT exts prms m () -- | insert extensional state. since v1.2.0. insertVault :: Key a -> a -> ActionT exts prms m () -- | adjust extensional state. since v1.2.0. adjustVault :: (a -> a) -> Key a -> ActionT exts prms m () -- | delete extensional state. since v1.2.0. deleteVault :: Key a -> ActionT exts prms 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 exts prms m () module Control.Monad.Apiary.Filter.Capture -- | check first path and drill down. since 0.11.0. path :: Monad actM => Text -> Filter' exts actM m fetch :: (k prms, KnownSymbol k, Path p, Monad actM) => proxy (k := p) -> Maybe Html -> Filter exts actM m prms ((k := p) : prms) -- | get first path and drill down. since 0.11.0. fetch' :: (k prms, KnownSymbol k, Path p, Monad actM) => proxy k -> proxy' p -> Maybe Html -> Filter exts actM m prms ((k := p) : prms) anyPath :: (Monad m, Monad actM) => Filter' exts actM m restPath :: (k prms, KnownSymbol k, Monad m, Monad actM) => proxy k -> Maybe Html -> Filter exts actM m prms ((k := [Text]) : prms) module Control.Monad.Apiary.Filter -- | routing filter type Filter exts actM m inp out = ApiaryT exts out actM m () -> ApiaryT exts inp actM m () -- | routing filter(without modify parameter dictionary) type Filter' exts actM m = forall prms. Filter exts actM m prms prms -- | filter by HTTP method. since 0.1.0.0. -- --
-- method GET -- stdmethod -- method "HOGE" -- non standard method --method :: Monad actM => Method -> Filter' exts actM m -- | http/0.9 only accepted fiter. since 0.5.0.0. http09 :: Monad actM => Filter' exts actM m -- | http/1.0 only accepted fiter. since 0.5.0.0. http10 :: Monad actM => Filter' exts actM m -- | http/1.1 only accepted fiter. since 0.5.0.0. http11 :: Monad actM => Filter' exts actM m -- | filter by rootPattern of ApiaryConfig. root :: (Monad m, Monad actM) => Filter' exts actM m -- | capture QuasiQuoter. since 0.1.0.0. -- -- example: -- --
-- [capture|/path|] -- first path == "path" -- [capture|/int/foo::Int|] -- first path == "int" && get 2nd path as Int. -- [capture|/bar::Int/baz::Double|] -- get first path as Int and get 2nd path as Double. -- [capture|/**baz|] -- feed greedy and get all path as [Text] (since 0.17.0). ---- -- this QQ can convert pure function easily. -- --
-- [capture|foofoo::Int|] == path "path" . fetch (Proxy :: Proxy ("foo" := Int)) . endPath
-- [capture|barbar::Int/**rest|] == path "path" . fetch (Proxy :: Proxy ("foo" := Int)) . restPath (Proxy :: Proxy "rest")
--
capture :: QuasiQuoter
-- | add document to query parameter filter.
--
-- -- [key|key|] ?? "document" =: pInt --(??) :: proxy key -> Html -> QueryKey key -- | get first matched paramerer. since 0.5.0.0. -- --
-- [key|key|] =: pInt --(=:) :: (HasDesc query, MonadIO actM, ReqParam v, KnownSymbol k, k prms) => query k -> proxy v -> Filter exts actM m prms ((k := v) : prms) -- | get one matched paramerer. since 0.5.0.0. -- -- when more one parameger given, not matched. -- --
-- [key|key|] =!: pInt --(=!:) :: (HasDesc query, MonadIO actM, ReqParam v, KnownSymbol k, k prms) => query k -> proxy v -> Filter exts actM m prms ((k := v) : prms) -- | get optional first paramerer. since 0.5.0.0. -- -- when illegal type parameter given, fail match(don't give Nothing). -- --
-- [key|key|] =?: pInt --(=?:) :: (HasDesc query, MonadIO actM, ReqParam v, KnownSymbol k, k prms) => query k -> proxy v -> Filter exts actM m prms ((k := Maybe v) : prms) -- | get optional first paramerer with default. since 0.16.0. -- -- when illegal type parameter given, fail match(don't give Nothing). -- --
-- [key|key|] =!?: (0 :: Int) --(=?!:) :: (HasDesc query, MonadIO actM, Show v, ReqParam v, KnownSymbol k, k prms) => query k -> v -> Filter exts actM m prms ((k := v) : prms) -- | get many paramerer. since 0.5.0.0. -- --
-- [key|key|] =*: pInt --(=*:) :: (HasDesc query, MonadIO actM, ReqParam v, KnownSymbol k, k prms) => query k -> proxy v -> Filter exts actM m prms ((k := [v]) : prms) -- | get some paramerer. since 0.5.0.0. -- --
-- [key|key|] =+: pInt --(=+:) :: (HasDesc query, MonadIO actM, ReqParam v, KnownSymbol k, k prms) => query k -> proxy v -> Filter exts actM m prms ((k := [v]) : prms) -- | get existance of key only query parameter. since v0.17.0. switchQuery :: (HasDesc proxy, MonadIO actM, KnownSymbol k, k prms) => proxy k -> Filter exts actM m prms ((k := Bool) : prms) -- | check whether to exists specified valued header or not. since 0.6.0.0. eqHeader :: (KnownSymbol k, Monad actM) => proxy k -> ByteString -> Filter' exts actM m -- | filter by header and get first. since 0.6.0.0. header :: (KnownSymbol k, Monad actM, k prms) => proxy k -> Filter exts actM m prms ((k := ByteString) : prms) -- | filter by JSON typed body. since 2.0.0. jsonReqBody :: (KnownSymbol k, MonadIO actM, k prms, FromJSON a) => proxy k -> Filter exts actM m prms ((k := a) : prms) -- | require Accept header and set response Content-Type. since 0.16.0. accept :: Monad actM => ContentType -> Filter' exts actM m -- | filter by ssl accessed. since 0.1.0.0. ssl :: Monad actM => Filter' exts actM m class HasDesc (a :: Symbol -> *) queryDesc :: HasDesc a => a key -> Maybe Html newtype QueryKey (key :: Symbol) QueryKey :: Maybe Html -> QueryKey [queryKeyDesc] :: QueryKey -> Maybe Html query :: (k prms, MonadIO actM, KnownSymbol k, ReqParam v, HasDesc query, Strategy strategy) => query k -> strategy v -> Filter exts actM m prms (SNext strategy k v prms) -- | http version filter. since 0.5.0.0. httpVersion :: Monad actM => HttpVersion -> Html -> Filter' exts actM m -- | low level filter function. function :: Monad actM => (Doc -> Doc) -> (Store prms -> Request -> Maybe (Store prms')) -> Filter exts actM m prms prms' -- | filter and append argument. function' :: (KnownSymbol key, Monad actM, key prms) => (Doc -> Doc) -> (Request -> Maybe (proxy key, prm)) -> Filter exts actM m prms ((key := prm) : prms) -- | filter only(not modify arguments). function_ :: Monad actM => (Doc -> Doc) -> (Request -> Bool) -> Filter' exts actM m -- | filter by action. since 1.3.0. focus :: Monad actM => (Doc -> Doc) -> Maybe Method -> (Path prms' (ActionT exts '[] actM) () -> Path prms (ActionT exts '[] actM) ()) -> Filter exts actM m prms prms' data Doc DocRoot :: Doc -> Doc DocMethod :: Method -> Doc -> Doc DocQuery :: Text -> StrategyRep -> QueryRep -> (Maybe Html) -> Doc -> Doc DocPrecondition :: Html -> Doc -> Doc DocAccept :: ByteString -> Doc -> Doc instance Control.Monad.Apiary.Filter.HasDesc Control.Monad.Apiary.Filter.QueryKey instance Control.Monad.Apiary.Filter.HasDesc Data.Proxy.Proxy instance Control.Monad.Apiary.Filter.HasDesc Data.Apiary.SProxy.SProxy module Control.Monad.Apiary -- | Apiary monad. since 0.8.0.0. data ApiaryT exts prms actM m a -- | run Apiary monad. runApiaryTWith :: (Monad actM, Monad m) => (forall b. actM b -> IO b) -> (Application -> m a) -> Initializer m '[] exts -> ApiaryConfig -> ApiaryT exts '[] actM m () -> m a runApiaryWith :: Monad m => (Application -> m a) -> Initializer m '[] exts -> ApiaryConfig -> ApiaryT exts '[] IO m () -> m a runApiary :: Monad m => (Application -> m a) -> ApiaryConfig -> ApiaryT '[] '[] IO m () -> m a -- | get Application from Apiary monad. since 2.0.0. getApiaryTWith :: (Monad actM, Monad m) => (forall b. actM b -> IO b) -> Initializer m '[] exts -> ApiaryConfig -> ApiaryT exts '[] actM m () -> m Application getApiaryWith :: Monad m => Initializer m '[] exts -> ApiaryConfig -> ApiaryT exts '[] IO m () -> m Application getApiary :: Monad m => ApiaryConfig -> ApiaryT '[] '[] IO m () -> m Application data ApiaryConfig ApiaryConfig :: Application -> Status -> ResponseHeaders -> ByteString -> Status -> ResponseHeaders -> Word64 -> Maybe FilePath -> [Text] -> (FilePath -> ByteString) -> ApiaryConfig -- | call when no handler matched. [notFound] :: ApiaryConfig -> Application -- | used unless call status function. [defaultStatus] :: ApiaryConfig -> Status -- | initial headers. [defaultHeaders] :: ApiaryConfig -> ResponseHeaders [defaultContentType] :: ApiaryConfig -> ByteString [failStatus] :: ApiaryConfig -> Status [failHeaders] :: ApiaryConfig -> ResponseHeaders -- | maximum request size, default to 5MB. since 2.0.0. [maxRequestSize] :: ApiaryConfig -> Word64 -- | where to store upload file. since 2.0.0. -- -- default to Nothing, which saves file content in memory. NOTE. -- once you set this value to some path, it's your responsibility to -- clean uploaded files. eg. move or remove it. [uploadFilePath] :: ApiaryConfig -> Maybe FilePath -- | used by root filter. [rootPattern] :: ApiaryConfig -> [Text] [mimeType] :: ApiaryConfig -> FilePath -> ByteString -- | splice ActionT to ApiaryT. action :: Monad actM => ActionT exts prms actM () -> ApiaryT exts prms actM m () -- | add middleware. -- -- please note that, this method just provide a shortcut to stack -- middleware. middlewares are added to whole Apiary application rather -- than specific route. middleware :: Monad actM => Middleware -> ApiaryT exts prms actM m () -- | API document group. since 0.12.0.0. -- -- only top level group recognized. group :: Text -> Filter' exts actM m -- | add API document. since 0.12.0.0. -- -- It use only filters prior document, so you should be placed document -- directly in front of action. document :: Text -> Filter' exts actM m -- | add user defined precondition. since 0.13.0. precondition :: Html -> Filter' exts actM m -- | ignore next document. noDoc :: Filter' exts actM m -- | get Apiary configuration. apiaryConfig :: Monad actM => ApiaryT exts prms actM m ApiaryConfig -- | get Apiary extension. -- | Deprecated: use getExt apiaryExt :: (Has e exts, Monad actM) => proxy e -> ApiaryT exts prms actM m e module Web.Apiary.Heroku data Heroku data HerokuConfig HerokuConfig :: Int -> String -> Maybe String -> ApiaryConfig -> HerokuConfig [defaultPort] :: HerokuConfig -> Int [herokuExecutableName] :: HerokuConfig -> String [herokuAppName] :: HerokuConfig -> Maybe String [herokuApiaryConfig] :: HerokuConfig -> ApiaryConfig -- | use this function instead of runApiary in heroku app. since 0.18.0. -- -- this function provide: -- --
-- runApiaryTWith id (run 3000) exts def $ foo ---- -- to -- --
-- runHerokuTWith id run exts def $ foo --runHerokuTWith :: (MonadIO m, Monad actM) => (forall b. actM b -> IO b) -> (Int -> Application -> m a) -> Initializer m '[Heroku] exts -> HerokuConfig -> ApiaryT exts '[] actM m () -> m a getHerokuEnv :: Has Heroku exts => Text -> Extensions exts -> IO (Maybe Text) getHerokuEnv' :: Text -> Heroku -> IO (Maybe Text) instance Control.Monad.Apiary.Action.Internal.Extension Web.Apiary.Heroku.Heroku instance Data.Default.Class.Default Web.Apiary.Heroku.HerokuConfig module Web.Apiary -- | construct string literal proxy. -- --
-- [key|foo|] == (Proxy :: Proxy "foo") --key :: QuasiQuoter -- | Warning: use Web.Apiary in production. module Web.Apiary.Develop -- | send file contents as lazy bytestring response with detect -- Content-Type. since v1.2.0. file :: MonadIO m => FilePath -> Maybe FilePart -> ActionT exts prms m () -- | send file contents as lazy bytestring response. since v1.2.0. file' :: MonadIO m => FilePath -> Maybe FilePart -> ActionT exts prms m ()