Jsonrpc.Request (finch_jsonrpc v0.1.0) View Source

Jsonrpc.Request represents a JSONRPC 2.0 request, as documented in the JSON-RPC 2.0 specification

Link to this section Summary

Functions

new creates a new Jsonrpc.Request. It takes a list of options. The options are

new/2 takes a request or a list of requests and adds a new request to the list. The options are the same as new/1. This function allows to chain multiple new calls together to create a list of RPC requests that can be send as a batch request.

order can be used to order a list of requests that are created by new/1 and new/2. This will overwrite ids that were given when creating the requests! It will guarantee the right order when new/1 and new/2 were used.

Link to this section Types

Specs

t() :: %Jsonrpc.Request{
  id: String.t() | integer() | nil,
  jsonrpc: String.t(),
  method: String.t(),
  params: any() | [any()]
}

Link to this section Functions

Specs

new(keyword()) :: t()

new creates a new Jsonrpc.Request. It takes a list of options. The options are:

  • method: the method of the RPC request as a string. This field is required.
  • params: the parameters of the request.
  • id: the id of the request. When not given, the time the request was created in unix time in milliseconds is used as the ID.

new can be piped with another new call to create a list of requests that can be send as a batch RPC request. See new/2

Example

Jsonrpc.Request.new(method: "callOne", params: "example", id: "1")

Specs

new(t() | [t()], keyword()) :: [t()]

new/2 takes a request or a list of requests and adds a new request to the list. The options are the same as new/1. This function allows to chain multiple new calls together to create a list of RPC requests that can be send as a batch request.

Example

Jsonrpc.Request.new(method: "callOne")
|> Jsonrpc.Request.new(method: "callTwo")
|> Jsonrpc.call(name: :example, url: "https://finchjsonrpc.redmaner.com")
Link to this function

order(req_list, starting_number \\ 1)

View Source

Specs

order([t()], integer()) :: [t()]

order can be used to order a list of requests that are created by new/1 and new/2. This will overwrite ids that were given when creating the requests! It will guarantee the right order when new/1 and new/2 were used.

Example

Jsonrpc.Request.new(method: "callOne")
|> Jsonrpc.Request.new(method: "callTwo")
|> Jsonrpc.Request.order(1)
|> Jsonrpc.call(name: :example, url: "https://finchjsonrpc.redmaner.com")