Vibe.d rest & web service?

Jacob Carlborg doob at me.com
Wed Feb 7 19:50:31 UTC 2018


On 2018-02-07 18:04, 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;
>          }
>      }
> }

Have you tried this?

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list