On Sunday, 28 July 2019 at 14:42:48 UTC, Robert M. Münch wrote:
On 2019-07-28 14:14:06 +0000, Sebastiaan Koppe said:

I am using https://dlang.org/spec/expression.html#import_expressions for text files. Don't know if it works on binary files as well.

And this works than good together with the vibe framework? So, it's not requiring or forcing one to use files or databases?

Haven't tested it, but something like this:

---
import vibe.core.core : runApplication;
import vibe.http.server;

void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
        if (req.path == "/file.txt")
                res.writeBody(import("file.txt"), "text/plain");
}

void main()
{
        auto settings = new HTTPServerSettings;
        settings.port = 8080;
        settings.bindAddresses = ["::1", "127.0.0.1"];

        auto l = listenHTTP(settings, &handleRequest);
        scope (exit) l.stopListening();

        runApplication();
}
---

Of course you may want to use the router or the rest generator for this. See the examples in the repo.

Reply via email to