⭕️ N2O: Haskell
Switch branches/tags
Nothing to show
Clone or download
Latest commit 9e68a94 Nov 10, 2018
Failed to load latest commit information.
core cabal descriptions Nov 9, 2018
man note Oct 31, 2018
nitro cabal descriptions Nov 9, 2018
protocols cabal descriptions Nov 9, 2018
samples cabal descriptions Nov 9, 2018
web Fix security issue Nov 10, 2018
.gitignore Ignore cabal.config Oct 30, 2018
.travis.yml Add travis file Oct 30, 2018
CNAME publication Oct 29, 2018
ChangeLog.md readme Oct 30, 2018
README.md Fix the sample code Nov 5, 2018
Synrc Neo.svg missing files Oct 30, 2018
haskell.css missing files Oct 30, 2018
index.html typo Oct 31, 2018
stack.yaml Get rid of bert dep Nov 1, 2018


N2O for Haskell

Build Status


  • Endpoints: poor man's WebSocket and static HTTP server
  • Formatters: BERT
  • Protocols: CLIENT, 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

Extensions and imports

{-# LANGUAGE OverloadedStrings #-}
module Main (main) where

import Network.N2O
import Network.N2O.Web
import Network.N2O.Protocols hiding (Init)
import Web.Nitro

Static Server and Page Router

data Example = Greet deriving (Show, Eq, Read)
main = runServer "localhost" 3000 cx
cx = mkCx{ cxMiddleware=[router]
         , cxProtos = [nitroProto]
         , cxDePickle = defDePickle
         , cxPickle = defPickle
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=handle}

Nitro Page Sample

index Init = do
  updateText "system" "What is your name?"
  wireEl 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 _ = lift $ putStrLn "Unknown event" >> return Empty
about Init =
  updateText "app" "This is the N2O Hello World App"
about ev = do
  lift $ putStrLn ("Unknown event " <> show ev)
  return Empty


  • Andy Melnikov
  • Marat Khafizov
  • Maxim Sokhatsky