This version can be pinned in stack with:fn-0.1.4.0@sha256:ea3c1648d83af7f434a371e760976397f8eb642b1b2d5eeb886d316dea7f5b24,1334
Module documentation for 0.1.4.0
Fn (eff-enn) - a functional web framework.
Or, how to do away with the monad transformers, and just use plain
functions.
Example
See the example application in the repository for a full usage, but a minimal application is the following:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp
import qualified Network.Wai.Util as W
import Web.Fn
data Ctxt = Ctxt { _req :: Request
}
makeLenses ''Ctxt
instance RequestContext Ctxt where
requestLens = req
initializer :: IO Ctxt
initializer = return (Ctxt defaultRequest)
main :: IO ()
main = do context <- initializer
run 8000 $ toWAI context app
app :: Ctxt -> IO Response
app ctxt =
route ctxt [ end ==> index
, path "foo" // segment // path "baz" /? param "id" ==> handler]
`fallthrough` notFoundText "Page not found."
index :: IO (Maybe Response)
index = okText "This is the index page! Try /foo/bar/baz?id=10"
handler :: Text -> Int -> Ctxt -> IO (Maybe Response)
handler fragment i _ = okText (fragment <> " - " <> T.pack (show i))
0.1.4.0 Daniel Pattersion [email protected] 2015-11-4
Move ctxt
back to first parameter passed to handlers, via more
continuations.
0.1.3.1 Daniel Pattersion [email protected] 2015-10-31
Add method
matcher to match against HTTP method.
0.1.3.0 Daniel Patterson [email protected] 2015-10-30
Allow nested calls to route
, by changing Request
in
ctxt
. This necesitated changing it so that the ctxt
is passed
to handlers last , instead of first, because we need to have
completed matching before we can change the request.
Add anything
route matcher that matches anything.
Add paramMany
matcher that returns a list of values for the
given query param.
Change param
to fail if more than one value is in query string.
0.1.2.0 Daniel Pattersion [email protected] 2015-10-27
Rename paramOptional
to paramOpt
, to match fn-extra
’s Heist
naming of attr
and attrOpt
. Remove paramPresent
, because you
can get that behavior by parsing to Text
.
0.1.1.0 Daniel Patterson [email protected] 2015-10-26
Rename Param
class to FromParam
.
0.1.0.0 Daniel Patterson [email protected] 2015-10-25
Initial release.
Stackage is a service provided by the
Haskell Foundation
│ Originally developed by
FP Complete