fn: A functional web framework.

[ library, web ] [ Propose Tags ]

Please see README.

[Skip to Readme]




Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,, (info)
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), blaze-builder, bytestring, http-types, text, wai [details]
License ISC
Copyright 2015 Daniel Patterson
Author Daniel Patterson <dbp@dbpmail.net>
Maintainer dbp@dbpmail.net
Category Web
Home page http://github.com/dbp/fn#readme
Source repo head: git clone https://github.com/dbp/fn
Uploaded by DanielPatterson at 2015-10-25T19:30:32Z
Distributions LTSHaskell:, NixOS:, Stackage:
Reverse Dependencies 1 direct, 1 indirect [details]
Downloads 8177 total (35 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-11-17 [all 2 reports]

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, 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 :: Ctxt -> Text -> Int -> IO (Maybe Response)
handler _ fragment i = okText (fragment <> " - " <> T.pack (show i))

Part of the design of Fn is that you won't need a suite of fn-foo libraries that generally serve to adapt the functions from foo to the monad transformer stack of the web framework of choice (we may add an fn-extra package with a few helpers in it in the future, but it'll be small). Still, it's helpful to know what are common tools that are well designed and tested, so here are a list (those marked with [*] are used in the example application included in the repository):

  • warp[*]: perhaps obvious, but you will need to choose an HTTP server to use with your Fn application, and warp is the defacto standard for applications that use the WAI interface that Fn does.
  • heist[*]: a wonderful templating system that is both really simple (the templates are just html) and powerful (any html tag can be bound to run haskell code). This may be the one place where we may add some adaptors, as it would be wonderful to have splices (those haskell-bound html tags) that were normal functions, rather than monadic.
  • postgresql-simple[*]: a well designed interface to PostgreSQL; ofter the lower level way to interact with the database (setting up connections, etc), if you use a higher level, safer abstraction like opaleye (below) for actual queries. Use it with resource-pool[*] to have it manage many connections.
  • opaleye: a type-safe composable way to write database queries against PostgreSQL.
  • hedis[*]: a full-featured client for the key-value store Redis.
  • logging[*]: a simple library for writing log messages, which allow you to change the logging level and suppress some subset of messages.
  • hspec[*]: a full-featured testing framework. Use with hspec-wai[*] - though the latter could use some work to make it do everything it needs to!
  • wai-session[*]: Combine with something like wai-session-clientsession[*] to store session data in encrypted cookies (like, who a user is logged in as).