This is the example hello world.
import vibe.d;
import std.file;
import std.stdio;
int c = 0;
shared static this()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, &hello);
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}
void hello(HTTPServerRequest req, HTTPServerResponse res)
{
string str = format("Count: %d", c++);
writefln("%s", str);
res.writeBody(str);
writefln("%s", str);
}
/*
Console output:
Listening for HTTP requests on ::1:8080
Listening for HTTP requests on 127.0.0.1:8080
Please open http://127.0.0.1:8080/ in your browser.
Count: 0
Count: 0
Count: 1
Count: 1
*/
The method hello is called twice, though there is only one response.