Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martin-volf/elm-jsonrpc
JSON RPC client for Elm
https://github.com/martin-volf/elm-jsonrpc
elm elm-lang json-rpc-client
Last synced: about 1 month ago
JSON representation
JSON RPC client for Elm
- Host: GitHub
- URL: https://github.com/martin-volf/elm-jsonrpc
- Owner: martin-volf
- License: mit
- Created: 2017-07-19T13:12:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T11:05:10.000Z (about 7 years ago)
- Last Synced: 2024-10-21T18:22:17.398Z (2 months ago)
- Topics: elm, elm-lang, json-rpc-client
- Language: Elm
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-jsonrpc
`elm-jsonrpc` is a simple JSON RPC request building and, more importantly,
request chaining tool. You will not need such tool if you do not plan to send
more than one or two RPC requests in a batch. On the other hand, if you need
to send several requests one depending on the other, handling errors and
passing results may become troublesome.## Installation
```bash
elm package install martin-volf/elm-jsonrpc
```## Example
```elm
requestOp : String -> Int -> Int -> JsonRPC.Command Ctx Msg Int
requestOp op a b =
JsonRPC.request
op
[ JsonRPC.simpleParam "a" (toString a), JsonRPC.simpleParam "b" (toString b) ]
Decode.intrequestPlus : Int -> Int -> JsonRPC.Command Ctx Msg Int
requestPlus =
requestOp "plus"requestMinus : Int -> Int -> JsonRPC.Command Ctx Msg Int
requestMinus =
requestOp "minus"requestTimes : Int -> Int -> JsonRPC.Command Ctx Msg Int
requestTimes =
requestOp "times"requestDiv : Int -> Int -> JsonRPC.Command Ctx Msg Int
requestDiv =
requestOp "div"{-| Let the server compute (1 + 2) * (3 - 4)
-}
compoundRequest : JsonRPC.Command Ctx Msg Int
compoundRequest =
requestPlus 1 2
|> JsonRPC.andThen
(\sum ->
requestMinus 3 4
|> JsonRPC.andThen (requestTimes sum)
)
```