WebsockexAdapter.JsonRpc (WebsockexAdapter v0.1.1)
View SourceJSON-RPC 2.0 request builder and response matcher.
Simple API builder for WebSocket APIs using JSON-RPC 2.0 protocol. Generates request functions with automatic ID tracking and correlation.
Summary
Functions
Builds a JSON-RPC 2.0 request with unique ID.
Generates RPC method functions with automatic request building.
Matches a JSON-RPC response to determine if it's a result or error.
Functions
Builds a JSON-RPC 2.0 request with unique ID.
Examples
iex> {:ok, request} = JsonRpc.build_request("public/auth", %{grant_type: "client_credentials"})
iex> request["method"]
"public/auth"
Generates RPC method functions with automatic request building.
Examples
defmodule MyApi do
use WebsockexAdapter.JsonRpc
defrpc :authenticate, "public/auth"
defrpc :subscribe, "public/subscribe"
defrpc :get_order_book, "public/get_order_book"
end
@spec match_response(map()) :: {:ok, term()} | {:error, {integer(), String.t()}} | {:notification, String.t(), map()}
Matches a JSON-RPC response to determine if it's a result or error.
Returns:
{:ok, result}
for successful responses{:error, {code, message}}
for JSON-RPC errors{:notification, method, params}
for notifications