Add HTTP server routes

This commit is contained in:
Les De Ridder 2017-02-14 22:29:40 +01:00
parent cd2356ae2a
commit ad25f4df24
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
1 changed files with 10 additions and 21 deletions

View File

@ -9,13 +9,6 @@ import vibe.d;
import vibe.data.json;
import vibe.textfilter.urlencode;
void helloWorld(HTTPServerRequest req,
HTTPServerResponse res)
{
res.writeBody("Hello");
}
class ApiRequest
{
}
@ -345,15 +338,6 @@ class ApiClient
shared static this()
{
auto router = new URLRouter;
router.get("/hello", &helloWorld);
auto settings = new HTTPServerSettings;
settings.sessionStore = new MemorySessionStore;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
auto apiClient = new ApiClient("nl_BE");
apiClient.connect();
@ -363,9 +347,14 @@ shared static this()
auto password = fromStringz(getpass("Password: ")).idup;
apiClient.login2(otp, password);
writeln("Account funds: " ~ apiClient.getAccountAvailable());
writeln("Card funds: " ~ apiClient.getCardAvailable());
writeln("Account funds: " ~ apiClient.getAccountAvailable());
writeln("Card funds: " ~ apiClient.getCardAvailable());
writeln("Account funds: " ~ apiClient.getAccountAvailable());
auto router = new URLRouter;
router.get("/account/available", delegate(HTTPServerRequest, HTTPServerResponse response) { response.writeBody(apiClient.getAccountAvailable()); });
router.get("/card/available", delegate(HTTPServerRequest, HTTPServerResponse response) { response.writeBody(apiClient.getCardAvailable()); });
auto settings = new HTTPServerSettings;
settings.sessionStore = new MemorySessionStore;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
}