jsonrpc.jsonrpc

JSON-RPC 2.0 protocol library.

The JSON-RPC 2.0 specification may be found at http://www.jsonrpc.org/specification

Members

Classes

RPCClient
class RPCClient(API, Transport = TCPTransport)

Implementation of a JSON-RPC client.

RPCServer
class RPCServer(API, Listener = TCPListener!API)

Implementation of a JSON-RPC server.

Enums

StandardErrorCode
enum StandardErrorCode

Standard error codes.

Functions

batchReq
auto batchReq(string method, JSONValue params, Flag!"notify" notify)

Create a BatchRequest to pass to an RPCClient's batch function.

deserialize
T deserialize(JSONValue json)

Deserialize a JSON Object to the specified aggregate D type.

executeMethod
Response executeMethod(Request request, API api)

Execute an RPC method and return the server's response.

handleClient
void handleClient(Transport transport, API api)

Handles all of an individual client's requests.

serialize
JSONValue serialize(T obj)

Serialize a struct to a JSON Object.

Structs

Request
struct Request

An RPC request constructed by the client to send to the RPC server.

Response
struct Response

The RPC server's response sent to clients.

Examples

enum hostname = "127.0.0.1";
enum ushort port = 54321;

interface API {
    long add(int a, int b);
}

class ServeFunctions {
    long add(int a, int b) { return a + b; }
}

void main(string[] args)
{
    import core.thread : Thread;
    import core.time : dur;

    auto t = new Thread({
        auto rpc = new RPCServer!ServeFunctions(hostname, port);
        rpc.listen();
    });
    t.isDaemon = true;
    t.start();
    Thread.sleep(dur!"seconds"(2));

    auto client = new RPCClient!API(hostname, port);
    assert(client.add(2, 2) == 4);
    assert(client.add(5, 6) == 11);
}

Meta

Authors

Ryan Frame