JSON-RPC

UnrealIRCd 6.0.5 will have a JSON-RPC API. This allows remote endpoints to query and control UnrealIRCd. For example for statistics.

This page starts with Configuration and Transport to quickly get you started. More details about the format are provided in the section JSON-RPC Protocol and the list of all API calls is in JSON-RPC Methods.

Configuration
You need to load the following modules at the moment (this procedure may change later): loadmodule "webserver"; loadmodule "rpc/rpc"; loadmodule "rpc/user"; loadmodule "rpc/channel";

Then you need to create a listen block with listen::options::rpc, and for HTTPS you would also have to create one or more api-user blocks. This is explained in Transport, see next.

UNIX domain socket
This is for local connections only. On the server side you have this: listen { file "/home/xyz/unrealircd/data/rpc.sock"; options { rpc; } } Then simply connect to the socket and you can issue JSON-RPC requests directly. Example: $ nc -U ~/unrealircd/data/rpc.sock {"jsonrpc": "2.0", "method": "channel.list", "params": {}, "id": 123} {"jsonrpc": "2.0", "method": "channel.list", "id": 123, "response": {"list": []}}

There is no authentication being done, as only local users can use this and the socket is only readable/writable by the user running UnrealIRCd by default (rwx--).

You can issue multiple requests (even in parallel, no need to wait for the response). The connection is not closed. The connection is only closed if some fatal JSON parsing error is encountered such as a missing. Normally that should never happen. Other errors such as an unknown method being called, invalid parameter count, etc. are not fatal.

HTTPS POST
On the server side this requires you to open up a port and add at least one api user: listen { ip *; port 8000; options { rpc; } }

rpc-user apiuser { match { ip 192.168.*; } password "password"; }

Then do a  request to   with the JSON request. Example: curl -s --insecure -X POST -d '{"jsonrpc": "2.0", "method": "channel.list", "params": {}, "id": 123}' https://apiuser:password@127.0.0.1:8000/api The connection is closed after processing the request. If you want to issue another API call then do a new HTTPS POST. If you want streaming requests/responses, use HTTPS Websocket (see next section).

HTTPS Websocket
On the server side the config is the same as for HTTP POST. You open up a port and have at least one api user: listen { ip *; port 8000; options { rpc; } }

rpc-user apiuser { match { ip 192.168.*; } password "password"; }

Make a HTTPS websocket connection and then you can send JSON requests. Eg: {"jsonrpc": "2.0", "method": "channel.list", "params": {}, "id": 123} The connection is kept open so you can issue more JSON-RPC requests. You may also send multiple requests in parallel, you don't have to wait for a response. The connection is only closed upon:
 * A fatal error, such as a JSON parsing error (obviously should never happen)
 * A certain timeout (currently rather low!)

JSON-RPC Protocol
The JSON request/responses follow the JSON-RPC 2.0 specification.

Request
This is an example query. It calls the  method with empty parameters: {"jsonrpc": "2.0", "method": "channel.list", "params": {}, "id": 123}

Response
If succesful, UnrealIRCd will reply with a response object. Here's an example if there are 0 channels: {"jsonrpc": "2.0", "method": "channel.list", "id": 123, "response": {"list": []}}

The response will naturally be different for each method. And as you can see, the  is included so the client application can track request/responses.

Error
A request may also result in an error instead of a response object. Here's an example error object that UnrealIRCd may send: {"jsonrpc": "2.0", "method": "qwerty", "id": 123, "error": {"code": -32601, "message": "Unsupported method"}}

TODO: Document error codes

JSON-RPC Methods
Currently only these are implemented:
 * user.list
 * user.get
 * channel.list