Use and provide services using JSON-RPC!
Transport | Client | Server |
---|---|---|
HTTP | Yes | Planned |
Websocket | Yes | Planned |
TCP | Yes | Yes |
Custom transports can be easily created. Have a look at JsonRpc::TcpClient
.
Here's a quick HTTP client getting your bitcoin testnet wallets balance:
# Sample code for Bitcoin RPC:
require "json_rpc"
# Set up the HTTP client
http_client = HTTP::Client.new("localhost", 18332)
http_client.basic_auth "rpc_user", "rpc_password"
# Turn it into a JSON-RPC client
client = JsonRpc::HttpClient.new http_client
# Check your balance!
pp client.call(Float64, "getbalance")
But there's more to find in samples/
:
For a simple case, see tcp_client.cr and tcp_server.cr.
If you want to see a full application, have a look at tcp_chat.cr.
Add this to your application's shard.yml
:
dependencies:
json_rpc:
github: Papierkorb/json_rpc
shards install
crystal spec
Connect all the things