class

JSON::RPC::Client

Inherits Reference < Object

A JSON-RPC 2.0 client. Builds requests, hands them to a {Transport}, and decodes the responses — raising {Error} for protocol errors and {TransportError} for transport failures.

client = JSON::RPC::Client.new("http://localhost:8080/rpc")
sum = client.call("add", {a: 2, b: 3}).as_i
client.notify("log", {level: "info", text: "done"})

Constructors

new(transport : Transport)
Source
new(uri : String | URI, headers : HTTP::Headers = HTTP::Headers.new)

Convenience constructor that builds an {HTTPTransport} for uri.

Source

Instance methods

call(method : String, params = nil) : JSON::Any

Invokes method with params and returns the result.

params may be any JSON-serializable value, or nil to send no params member. Raises {Error} when the peer reports a JSON-RPC error and {TransportError} on a transport failure.

Source
notify(method : String, params = nil) : Nil

Sends a notification: a request with no id, for which the peer must not reply. Returns immediately after the transport accepts the request.

Source
transport

The transport used to deliver requests.

Source