Encoding, decoding and classification of JSON-RPC 2.0 messages.
The 2025-11-25 revision carries exactly one JSON-RPC message per transport frame (HTTP request batching was removed), so this module operates on single messages.
Decoded messages are returned as tagged tuples so callers can branch on the kind without re-inspecting the map:
{:request, id, method, params}{:notification, method, params}{:response, id, result}{:error_response, id, error}
Summary
Functions
Classifies an already-decoded JSON term (a map) into a tagged message.
Parses a JSON binary into a single classified JSON-RPC message.
Encodes a message map to a JSON binary.
Builds a JSON-RPC error response map. id may be nil for errors that cannot be
associated with a request (e.g. parse errors), serialized as JSON null.
Builds a JSON-RPC notification map.
Builds a JSON-RPC request map.
Builds a successful JSON-RPC response map.
Types
Functions
@spec classify(term()) :: {:ok, decoded()} | {:error, Urchin.Error.t()}
Classifies an already-decoded JSON term (a map) into a tagged message.
Arrays are rejected: this revision does not support JSON-RPC batching.
@spec decode(binary()) :: {:ok, decoded()} | {:error, Urchin.Error.t()}
Parses a JSON binary into a single classified JSON-RPC message.
Returns {:ok, decoded} or {:error, Urchin.Error.t()}. Malformed JSON yields a
parse error; structurally invalid messages yield an invalid-request error.
Encodes a message map to a JSON binary.
@spec error_response(id() | nil, Urchin.Error.t()) :: map()
Builds a JSON-RPC error response map. id may be nil for errors that cannot be
associated with a request (e.g. parse errors), serialized as JSON null.
Builds a JSON-RPC notification map.
Builds a JSON-RPC request map.
Builds a successful JSON-RPC response map.