retort v2.6.1 Retort.Response View Source

A JSON-RPC Response object

Link to this section Summary

Functions

Generates error response with the given message and corresponding code

Converts JSON decoded map with String.t keys to t

Decodes a JSON-encoded string back to a t

Link to this section Types

Link to this type t() View Source
t() :: %Retort.Response{error: Retort.Response.Error.t | nil, id: integer | String.t | nil, jsonrpc: String.t, result: String.t | false | true | integer | float | [...] | %{} | nil}

Link to this section Functions

Generates error response with the given message and corresponding code

Link to this function from_json(map) View Source
from_json(%{required(binary) => any}) :: t | no_return

Converts JSON decoded map with String.t keys to t.

Link to this function from_string(string) View Source
from_string(binary) :: t | no_return

Decodes a JSON-encoded string back to a t.

Decode a successful response

iex> Retort.Response.from_string(~S|{“id”: 1, “jsonrpc”: “2.0”, “result”: true}|) %Retort.Response{error: nil, id: 1, jsonrpc: “2.0”, result: true}

Decode an error response with data

iex> Retort.Response.from_string( …> ~S|{“error”: {“code”: -32602, “data”: [“foo”], “message”: “Invalid params”}, “id”: 2, “jsonrpc”: “2.0”}| …> ) %Retort.Response{

  error: %Retort.Response.Error{code: -32602, data: ["foo"], message: "Invalid params"},
  id: 2,
  jsonrpc: "2.0",
  result: nil

}

Decode an error response without data

iex> Retort.Response.from_string( …> ~S|{“error”: {“code”: -32600, “message”: “Invalid Request”}, “id”: 3, “jsonrpc”: “2.0”}| …> ) %Retort.Response{

error: %Retort.Response.Error{code: -32600, message: "Invalid Request"},
id: 3,
jsonrpc: "2.0",
result: nil

}