liwenjun/elm-jsonrpc/1.0.0

NOTE: the latest version is 2.0.0

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/liwenjun/elm-jsonrpc exists but has no tag 1.0.0; Software Heritage has no tag 1.0.0 for it; no fork with tag 1.0.0 found (2 same-name repos checked); no cached copy. Use another version.

Details

JsonRpc

一个通用的JsonRpc-V2调用接口,帮助实现JsonRpc客户端应用。

数据结构

Http 数据结构

type alias WebData a =
Result Error a

Http 返回数据定义

JsonRpc 数据结构

type Response a
= InnerResult a
| InnerError RpcError

JsonRpc 响应结果

type alias RpcError =
{ code : Int
, message : String
, data : Maybe String
}

JsonRpc 返回错误格式定义

type alias RpcData a =
WebData (Response a)

基于 http 的 JsonRpc 响应结果

用于 Task 调用的 JsonRpc 数据结构

type alias TaskData a =
Task Error a

Http Task 调用返回数据定义

type alias TaskRpcData a =
TaskData (Response a)

基于 http Task 调用 JsonRpc 返回结果

便于用户使用的 JsonRpc 数据结构

type Data a
= RpcResult a
| RpcErr RpcError
| HttpErr Error

便于处理的返回结果

JsonRpc 调用参数结构

type alias Param =
{ url : String
, token : Maybe String
, method : String
, params : List ( String, Value )
}

调用参数

Cmd 方式调用

call : Param -> Decoder a -> (RpcData a -> msg) -> Cmd msg

HTTP 调用方法

callWithConfig : (Param -> Value) -> Param -> Decoder a -> (RpcData a -> msg) -> Cmd msg

HTTP调用方法,供定制扩展使用,如Zabbix调用。

Task 方式调用

callTask : Param -> Decoder a -> TaskRpcData a

HTTP Task调用方法

callWithConfigTask : (Param -> Value) -> Param -> Decoder a -> TaskRpcData a

HTTP Task 调用方法。扩展zabbix接口时,可以用这个函数。

辅助函数

返回结果平面化处理

flat : RpcData a -> Data a

将rpc调用的返回结果平面化处理

toResult : Data a -> Result String a

将平面化处理结果转换为Result

httpErrToString : Error -> String

Http.Error转换为String