Vibe.d rest & web service?
Seb
seb at wilzba.ch
Wed Feb 7 18:38:15 UTC 2018
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)
More information about the Digitalmars-d-learn
mailing list