The fn package

[Tags:library, test]

A Haskell web framework where you write plain old functions.

Provided you have 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.

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.


[Skip to Readme]

Properties

Versions 0.0.0.0, 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.3.0, 0.1.3.1, 0.1.4.0, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.3.0.0, 0.3.0.1 (info)
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), blaze-builder, bytestring, directory, filepath, http-types, text, unordered-containers, wai (>=3), wai-extra (>=3) [details]
License ISC
Copyright 2016 Position Development, LLC.
Author Daniel Patterson <dbp@dbpmail.net>
Maintainer workers@positiondev.com
Category Web
Home page http://github.com/positiondev/fn#readme
Source repository head: git clone https://github.com/positiondev/fn
Uploaded Fri Mar 11 15:22:53 UTC 2016 by DanielPatterson
Distributions LTSHaskell:0.3.0.1, NixOS:0.3.0.1, Stackage:0.3.0.1, Tumbleweed:0.3.0.1
Downloads 859 total (93 in the last 30 days)
Votes
1 []
Status Docs available [build log]
Last success reported on 2016-03-11 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for fn

Readme for fn-0.3.0.1

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 including database access, heist templates, sessions, etc.