json-rpc
Version, currently main branch1 version
- main branchlatestJun 2, 2026
github.com/plambert/json-rpc.cr
A small, transport-agnostic JSON-RPC 2.0 client for Crystal.
Installation
# Add this to your shard.yml
dependencies:
json-rpc:
github: plambert/json-rpc.cr
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
>= 1.19.0- License
- MIT
- Author
- Paul M. Lambert
Dependencies
Development Dependencies
- spectator~> 0.11gitlab: arctic-fox/spectatordev
README
json-rpc
A small, transport-agnostic JSON-RPC 2.0 client for Crystal.
The client builds and decodes the JSON-RPC envelope; a pluggable transport carries bytes to the
peer. An HTTP transport ships in the box, and the abstract JSON::RPC::Transport lets you speak
JSON-RPC over anything else (a Unix socket, an in-process stub for tests, a transport that handles
CSRF tokens, …).
Installation
Add the dependency to your shard.yml:
dependencies:
json-rpc:
github: plambert/json-rpc.cr
Then run shards install.
Usage
require "json-rpc"
client = JSON::RPC::Client.new("http://localhost:8080/rpc")
# Call a method and read the result (returned as JSON::Any).
sum = client.call("add", {a: 2, b: 3}).as_i
# Fire a notification (no id, no response expected).
client.notify("log", {level: "info", text: "started"})
Errors
- A JSON-RPC
errormember raisesJSON::RPC::Error, exposing#code,#message, and#data. - A transport-level failure (e.g. a non-2xx HTTP status) raises
JSON::RPC::TransportError, exposing#statuswhen the transport has a notion of one.
Both inherit from JSON::RPC::Exception.
Custom transports
Implement JSON::RPC::Transport#call(body : String) : String to control how requests are
delivered:
class MyTransport < JSON::RPC::Transport
def call(body : String) : String
# send `body`, return the raw response body
end
end
client = JSON::RPC::Client.new(MyTransport.new)
JSON::RPC::HTTPTransport is the default. Subclass it and override #post or #call to layer in
behavior such as token negotiation — this is exactly how
transmission-rpc handles Transmission's
X-Transmission-Session-Id CSRF dance.
Development
shards install
crystal spec -v --error-trace
crystal tool format
ameba
License
MIT
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Jun 2, 2026
- Crystal
>= 1.19.0- Indexed
- yes
Dependents
Repository
github.com/plambert/json-rpc.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Sep 21, 2026
- Synced
- Sep 21, 2026
- Versions
- 1