Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/athanclark/purescript-websockets-rpc
A simple subscription-esque RPC mechanism using WebSockets, ala the haskell websockets-rpc library (client only)
https://github.com/athanclark/purescript-websockets-rpc
purescript websockets websockets-rpc
Last synced: 6 days ago
JSON representation
A simple subscription-esque RPC mechanism using WebSockets, ala the haskell websockets-rpc library (client only)
- Host: GitHub
- URL: https://github.com/athanclark/purescript-websockets-rpc
- Owner: athanclark
- License: bsd-3-clause
- Created: 2017-03-07T04:32:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-11T16:45:19.000Z (over 7 years ago)
- Last Synced: 2024-12-09T23:48:19.937Z (25 days ago)
- Topics: purescript, websockets, websockets-rpc
- Language: PureScript
- Size: 56.6 KB
- Stars: 8
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
purescript-websockets-rpc
=======================for use with a [websockets-rpc](https://hackage.haskell.org/package/websockets-rpc)-compliant websocket server,
the [purescript-websocket-moderate](https://pursuit.purescript.org/packages/purescript-websocket-moderate) client
library, and [purescript-argonaut](https://github.com/purescript-contrib/purescript-argonaut) json serialization
system.Example
-------```purescript
import WebSocket.RPC
import WebSocket (WEBSOCKET)data MySubDSL = Foo
deriving (EncodeJson, DecodeJson) -- you should figure this outdata MySupDSL = Bar
deriving (EncodeJson, DecodeJson)data MyRepDSL = Baz
deriving (EncodeJson, DecodeJson)data MyComDSL = Qux
deriving (EncodeJson, DecodeJson)myClient :: forall eff
. {url :: String, protocols :: Array String}
-> (WebSocketClientRPCT MyRepDSL MyComDSL (Eff _) Unit
myClient = rpcClient $ \dispatch -> do
-- could dispatch more than one subscription here
dispatch myClient'
where
myClient' :: RPCClient MySubDSL MySupDSL MyRepDSL MyComDSL (Eff (AllEffs eff))
myClient' =
{ subscription: Foo
, onReply: \{supply,cancel} Baz -> do
x <- randomInt 1 10
if x == 10 then cancel else supply Bar
, onComplete: \Qux ->
log "ayooo"
}
main :: Eff _ Unit
main =
execWebSocketClientRPCT $ myClient {url: "ws://localhost", protocols: []}
```see the `example/` folder for a working one