Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/o3/n2o
⭕️ N2O: Haskell Application Server
https://github.com/o3/n2o
haskell n2o
Last synced: about 3 hours ago
JSON representation
⭕️ N2O: Haskell Application Server
- Host: GitHub
- URL: https://github.com/o3/n2o
- Owner: o3
- License: bsd-3-clause
- Created: 2018-08-08T23:54:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-16T08:27:49.000Z (over 2 years ago)
- Last Synced: 2024-03-15T21:22:48.150Z (8 months ago)
- Topics: haskell, n2o
- Language: Haskell
- Homepage: https://n2o.o3.click
- Size: 288 KB
- Stars: 47
- Watchers: 8
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# N2O for Haskell
[![Build Status](https://travis-ci.org/xafizoff/n2o.svg?branch=master)](https://travis-ci.org/xafizoff/n2o)
Features
--------* Endpoints: poor man's WebSocket and static HTTP server
* Formatters: BERT
* Protocols: NITRO
* High Performance Protocol Relay
* Smallest possible codebase — 500 LOCN2O 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.Setup
-----```sh
stack build
stack exec n2o-sample
open http://localhost:3000/samples/static/index.html
```Nitro Protocol Demo
-------------------```haskell
{-# LANGUAGE FlexibleContexts, OverloadedStrings, DeriveGeneric, DeriveAnyClass #-}
module Main (main) whereimport 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)
```Credits
-------* Andy Melnikov
* Marat Khafizov
* Maxim Sokhatsky