fn: A functional web framework.

[ library, web ] [ Propose Tags ]

A Haskell web framework where you write plain old functions.

Provided you have stack installed, you can run this example like a shell script:

#!/usr/bin/env stack
-- stack --resolver lts-3.10 --install-ghc runghc --package fn
{-# 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]
Versions [RSS] [faq],,,,,,,,,,,, (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 2015 Daniel Patterson
Author Daniel Patterson <dbp@dbpmail.net>
Maintainer dbp@dbpmail.net
Category Web
Home page http://github.cxom/dbp/fn#readme
Source repo head: git clone https://github.com/dbp/fn
Uploaded by DanielPatterson at 2015-11-06T04:14:38Z
Distributions LTSHaskell:, NixOS:, Stackage:
Downloads 7757 total (38 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]




Maintainer's Corner

For package maintainers and hackage trustees


Readme for fn-

[back to package description]

Fn (eff-enn) - a functional web framework.

Or, how to do away with the monad transformers, and just use plain functions.


See the example application in the repository for a full usage including database access, heist templates, sessions, etc.