JsonRpcRequest

A Json-Rpc request that use TId as id type.

Constructors

this
this()

Members

Functions

hasParams
bool hasParams()
toJson
Json toJson()

Convert to Json.

toString
string toString()

Convert to a Json string.

Properties

requestId
TId requestId [@property getter]

Static functions

fromJson
JsonRpcRequest fromJson(Json src)

Parse from Json.

fromString
JsonRpcRequest fromString(string src)

Parse from a Json string.

make
JsonRpcRequest!TId make(TId id, string method, T params)
JsonRpcRequest!TId make(TId id, string method)

Create a new json request.

Variables

id
TId id;
Undocumented in source.
jsonrpc
string jsonrpc;

json rpc string

method
string method;

Json rpc method

params
Nullable!Json params;
Undocumented in source.

Examples

import vibe.data.json;

auto r1 = new JsonRpcRequest!int();
auto json = Json.emptyObject;
json["foo"] = 42;

r1.method = "foo";
r1.toString().should == `{"method":"foo","id":0,"jsonrpc":"2.0"}`;

auto r2 = new JsonRpcRequest!int();
r2.method = "foo";
r2.params = json;
r2.toString().should == `{"params":{"foo":42},"method":"foo","id":0,"jsonrpc":"2.0"}`;

auto r3 = deserializeJson!(JsonRpcRequest!int)(r1.toString());
r3.id.should == r1.id;
r3.params.should == r1.params;
r3.method.should == r1.method;

// string id:
auto r10 = new JsonRpcRequest!string();
r10.method = "foo";
r10.id = "bar";
r10.toString().should == `{"method":"foo","id":"bar","jsonrpc":"2.0"}`;

Meta