Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/positiondev/fn
A functional web framework
https://github.com/positiondev/fn
functional haskell web-framework
Last synced: 7 days ago
JSON representation
A functional web framework
- Host: GitHub
- URL: https://github.com/positiondev/fn
- Owner: positiondev
- Created: 2015-10-24T02:27:25.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-22T14:50:38.000Z (almost 3 years ago)
- Last Synced: 2024-04-26T00:30:54.110Z (6 months ago)
- Topics: functional, haskell, web-framework
- Language: Haskell
- Homepage: http://fnhaskell.com
- Size: 137 KB
- Stars: 33
- Watchers: 4
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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` directory for a full example, but a minimal
application is the following:```haskell
{-# 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.Fndata Ctxt = Ctxt { _req :: Request
}makeLenses ''Ctxt
instance RequestContext Ctxt where
requestLens = reqinitializer :: IO Ctxt
initializer = return (Ctxt defaultRequest)main :: IO ()
main = do context <- initializer
run 8000 $ toWAI context appapp :: 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 :: Text -> Int -> Ctxt -> IO (Maybe Response)
handler fragment i _ = okText (fragment <> " - " <> T.pack (show i))```