A Haskell web framework where you write plain old functions.
/Provided you have/ <https://github.com/commercialhaskell/stack#readme stack> /installed, you can run this example like a shell script (it'll listen on port 3000):/
' #!/usr/bin/env stack -- stack --resolver lts-5.5 --install-ghc runghc --package fn --package warp {-# LANGUAGE OverloadedStrings #-} import Data.Monoid ((<>)) import Data.Text (Text) import Network.Wai (Response) import Network.Wai.Handler.Warp (run) import Web.Fn
data Ctxt = Ctxt { _req :: FnRequest } instance RequestContext Ctxt where   getRequest = _req   setRequest c r = c { _req = r }
initializer :: IO Ctxt initializer = return (Ctxt defaultFnRequest)
main :: IO () main = do ctxt <- initializer   run 3000 $ toWAI ctxt site
site :: Ctxt -> IO Response site ctxt = route ctxt [ end ==> indexH   , path "echo" // param "msg" ==> echoH   , path "echo" // segment ==> echoH   ]  
fallthrough
notFoundText "Page not found."indexH :: Ctxt -> IO (Maybe Response) indexH _ = okText "Try visiting /echo?msg='hello' or /echo/hello"
echoH :: Ctxt -> Text -> IO (Maybe Response) echoH _ msg = okText $ "Echoing '" <> msg <> "'." '
Fn lets you write web code that just looks like normal Haskell code.
contain other data as well, like database connection pools, etc. This context will be passed to each of your handlers, updated with the current HTTP Request.
then routed to handler functions that have the appropriate number and type of arguments. These functions return 'IO (Maybe Response)', where 'Nothing' indicates to Fn that you want it to keep looking for matching routes.
from GHCi, 'forkIO', etc.
flexilibility to do anything you need to do with HTTP.
The name comes from the fact that Fn emphasizes functions (over monads), where all necessary data is passed via function arguments, and control flow is mediated by return values.
Package Version | Update ID | Released | Package Hub Version | Platforms | Subpackages |
---|---|---|---|---|---|
0.3.0.1-bp150.2.3 info | GA Release | 2018-08-01 | 15 |
|
|
0.3.0.1-bp150.2.5 info | GA Release | 2018-07-31 | 15 |
|
|
0.3.0.1-bp150.2.6 info | GA Release | 2018-07-30 | 15 |
|
|