On Wednesday, 7 February 2018 at 17:04:13 UTC, Nicholas Wilson wrote:
Is it possible to have some urls routed to serve content and some to receive JSON in the same class? Basically I want:

shared static this()
{
    auto router = new URLRouter;
    auto a = new MyInterface;
router.registerWebInterface(new MyInterface); //?? selective combination
    router.registerRestInterface(new MyInterface); //??
    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    settings.bindAddresses = ["::1","127.0.0.1"];
    listenHTTP(settings, router);
}

class MyInterface
{
    SomeData[] items;
    // Get
    void index()
    {
        render!("index.dt");
    }
    // Get
    void getPage()
    {
        render!("page.dt", items);
    }

    // REST -> receive d as JSON.
    void postGiveMeData(SomeData d)
    {
        synchronized
        {
            items ~= d;
        }
    }
}

How about using the normal Vibe.d Web Service?

An example from my WIP project vibe-by-example project:

https://github.com/wilzbach/vibe-d-by-example/blob/master/web/service.d


I also have a fork of vibe.web.web that adds additional convenience features to Vibe.d:

https://github.com/teamhackback/hb-web


(I have been struggling to get most of them merged upstream - https://github.com/vibe-d/vibe.d/pulls/wilzbach)

Reply via email to