Vibe.d rest & web service?

Nicholas Wilson iamthewilsonator at hotmail.com
Wed Feb 7 17:04:13 UTC 2018


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;
         }
     }
}


More information about the Digitalmars-d-learn mailing list