/
app.d
79 lines (66 loc) · 2.04 KB
/
app.d
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module app;
import vibe.vibe;
interface ITestAPI
{
@property ISub sub();
@method(HTTPMethod.POST) @path("other/path")
string info();
string getInfo();
@path("getCheck/:param/:param2") @method(HTTPMethod.GET)
string customParameters(string _param, string _param2);
@path("getCheck2/:param/:param2") @method(HTTPMethod.GET)
int customParameters2(int _param, bool _param2);
@path(":id/idtest1")
int testID1(int _id);
@path("idtest2")
int testID2(int id); // the special "id" parameter
int get(int id); // the special "id" parameter on "/"" path
int testKeyword(int body_, int const_);
}
interface ISub {
int get(int id);
}
class TestAPI : ITestAPI
{
SubAPI m_sub;
this() { m_sub = new SubAPI; }
@property SubAPI sub() { return m_sub; }
string getInfo() { return "description"; }
string info() { return "description2"; }
string customParameters(string _param, string _param2) { return _param ~ _param2; }
int customParameters2(int _param, bool _param2) { return _param2 ? _param : -_param; }
int testID1(int _id) { return _id; }
int testID2(int id) { return id; }
int get(int id) { return id; }
int testKeyword(int body_, int const_) { return body_ + const_; }
}
class SubAPI : ISub {
int get(int id) { return id; }
}
void runTest()
{
auto router = new URLRouter;
registerRestInterface!ITestAPI(router, new TestAPI, "/root/");
auto settings = new HTTPServerSettings;
settings.disableDistHost = true;
settings.port = 8000;
listenHTTP(settings, router);
auto api = new RestInterfaceClient!ITestAPI("http://127.0.0.1:8000/root/");
assert(api.getInfo() == "description");
assert(api.info() == "description2");
assert(api.customParameters("one", "two") == "onetwo");
assert(api.customParameters2(10, false) == -10);
assert(api.customParameters2(10, true) == 10);
assert(api.testID1(2) == 2);
assert(api.testID2(3) == 3);
assert(api.get(4) == 4);
assert(api.sub.get(5) == 5);
assert(api.testKeyword(3, 4) == 7);
exitEventLoop(true);
}
int main()
{
setLogLevel(LogLevel.debug_);
runTask(toDelegate(&runTest));
return runEventLoop();
}