retort v2.1.0 Retort.Response
A JSON-RPC Response object
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
Types
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}
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
.
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
}