SimpleTest

C++ code posted
created at 26 Apr 12:19

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    // Create a new type
    Json::Value personSchema;
    personSchema["name"][Schema::Type] = Schema::String;
    personSchema["age"][Schema::Type] = Schema::Int;
    personSchema["hasPenis"][Schema::Type] = Schema::Bool;
    personSchema["friend"][Schema::Type] = "person";
    personSchema["friend"][Schema::Optional] = true;
    staples.registerType("person", personSchema);

    // Register a function which uses that type
    Json::Value personToStringSchema;
    personToStringSchema["person"][Schema::Type] = "person";
    Staples::Service personToStringService("personToString",
            personToStringSchema,
            personToString);
    staples.registerService(personToStringService);

    // Make a request against that function
    Json::Value i;
    Json::Value o;
    i[Protocol::service]="personToString";
    i[Protocol::parameters]["person"]["name"] = "Sammedy sam";
    i[Protocol::parameters]["person"]["age"] = 22;
    i[Protocol::parameters]["person"]["hasPenis"] = true;
    i[Protocol::parameters]["person"]["friend"]["name"]="Terry";
    i[Protocol::parameters]["person"]["friend"]["age"]=29;
    i[Protocol::parameters]["person"]["friend"]["hasPenis"]=false;
    staples.dispatch(i, o);
    return (EXIT_SUCCESS);
}
1.25 KB in 5 ms with coderay