⭕️ N2O: Haskell Application Server
Switch branches/tags
Nothing to show
Clone or download
Latest commit d59323d Dec 16, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
man index Dec 16, 2018
src Cleanup debug output Nov 27, 2018
.gitignore Refactor all stuff Nov 26, 2018
CNAME Update CNAME Nov 27, 2018
ChangeLog.md readme Oct 30, 2018
LICENSE Add license file Nov 27, 2018
README.md Update readme Nov 26, 2018
Setup.hs Move subprojects to the separate repos Nov 27, 2018
index.html correct build commands Dec 16, 2018
n2o.cabal Move subprojects to the separate repos Nov 27, 2018
stack.yaml stack Dec 16, 2018


N2O for Haskell

Build Status


  • Endpoints: poor man's WebSocket and static HTTP server
  • Formatters: BERT
  • Protocols: NITRO
  • High Performance Protocol Relay
  • Smallest possible codebase — 500 LOC

N2O defines a way we scale protocols, database schema, applications and services across companies, formatters, views and presentation layers. At the core N2O folds a list of protocols and their handlers providing a minimal type-level specification for general purpose application protocol tract.

As example this Haskell version of N2O is shipped with Nitro protocol implementation, that listens the tract and push prerendered JavaScript events back to the channel. This smart and simple reactive way of client-server interaction first was used by Rusty Klophaus in his Nitrogen web framework, that was pushed forward since then in N2O by Andy Melnikov and Marat Khafizov.


stack build
stack exec n2o-sample
open http://localhost:3000/samples/static/index.html

Nitro Protocol Demo

{-# LANGUAGE FlexibleContexts, OverloadedStrings, DeriveGeneric, DeriveAnyClass #-}
module Main (main) where

import Network.N2O
import Network.N2O.Web hiding (Event)
import GHC.Generics (Generic)
import Data.Serialize (Serialize)

data Example = Greet deriving (Show, Eq, Generic, Serialize)

main = runServer "localhost" 3000 cx

cx :: Cx Example
cx = mkCx{ cxMiddleware=[router]
         , cxProtos = [nitroProto]

router cx@Context{cxReq=Req{reqPath=path}} =
  let handle = case path of
                  "/ws/samples/static/index.html" -> index
                  "/ws/samples/static/about.html" -> about
                  _ -> index
  in cx{cxHandler=mkHandler handle}

index Init = do
  updateText "system" "What is your name?"
  wire button{id_="send", postback=Just Greet, source=["name"]}
index (Message Greet) = do
  Just name <- get "name" -- wf:q/1
  updateText "system" ("Hello, " <> jsEscape name <> "!")
index ev = liftIO $ putStrLn ("Unknown event" <> show ev)
about Init = updateText "app" "This is the N2O Hello World App"
about ev = liftIO $ putStrLn ("Unknown event " <> show ev)


  • Andy Melnikov
  • Marat Khafizov
  • Maxim Sokhatsky