This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
JSON RPC client library
version 1.0.0
license MIT
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.0
Committed At 2017-10-06 10:52:08 UTC
elm-lang/http 1.0.0 <= v < 2.0.0 1.0.0
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

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

elm package install martin-volf/elm-jsonrpc

Example

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.int


requestPlus : 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)
            )