ghiliweld / wai-braid

braid protocol server in haskell WIP 🚧

Home Page:https://braid.news/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wai-braid

braid protocol server in haskell, implemented as wai middleware

my writeup on the braid protocol

Usage

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.Wai.Middleware.Braid (braidify, streamUpdates, hasSubscription, status209, Update, OutChannel(..), InChannel(..))
import Network.Wai
import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
import Network.Wai.Handler.Warp (run)
import Network.HTTP.Types.Status (status200)

instance OutChannel Chan where
    readChannel = readChan

instance InChannel Chan where
    writeChannel = writeChan
    
application src req respond = respond $ 
    if hasSubscription req 
    then responseStream status209 [("Content-Type", "text/plain")] $ streamUpdates src ["topic"]
    else responseLBS status200 [("Content-Type", "text/plain")] "Hello World"

main :: IO ()
main = newChan >>= \src -> run 3000 $ braidify src $ application src

example tests in cURL

curl output

About

braid protocol server in haskell WIP 🚧

https://braid.news/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Haskell 100.0%