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 = No.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

1 enum hostname = "127.0.0.1";
2 enum ushort port = 54321;
3 
4 interface API {
5     long add(int a, int b);
6 }
7 
8 class ServeFunctions {
9     long add(int a, int b) { return a + b; }
10 }
11 
12 void main(string[] args)
13 {
14     import core.thread : Thread;
15     import core.time : dur;
16 
17     auto t = new Thread({
18         auto rpc = new RPCServer!ServeFunctions(hostname, port);
19         rpc.listen();
20     });
21     t.isDaemon = true;
22     t.start();
23     Thread.sleep(dur!"seconds"(2));
24 
25     auto client = new RPCClient!API(hostname, port);
26     assert(client.add(2, 2) == 4);
27     assert(client.add(5, 6) == 11);
28 }

Meta

Authors

Ryan Frame