fn: A functional web framework.

[ library, web ] [ Propose Tags ]

Please see README.


[Skip to Readme]
Versions [faq] 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, 0.3.0.2 (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 Tue Oct 27 00:38:40 UTC 2015
Distributions LTSHaskell:0.3.0.2, NixOS:0.3.0.2, Stackage:0.3.0.2
Downloads 3376 total (169 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2015-10-27 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for fn-0.1.1.0

[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.

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