Vibe.d rest & web service?

Nicholas Wilson iamthewilsonator at hotmail.com
Thu Feb 8 20:21:39 UTC 2018


On Wednesday, 7 February 2018 at 18:47:05 UTC, Steven 
Schveighoffer wrote:
> Yes you can, but it's not pretty.
>
> interface MyInterface
> {
>    void postGiveMeData(SomeData d);
> }
>
> class MyInterfaceImpl : MyInterface
> {
>    void postGiveMeData(SomeData d) { ... }
>    void getPage() { ... }
>    void index() { ... }
> }
>
> auto myI = new MyInterfaceImpl;
> router.registerRestInterface(myI);
> router.get("/route/to/getPage", &myI.getPage);
> router.get("/route/to/index", &myI.index);
>
> This worked for me, but note that my "non-rest" function was 
> static, so I didn't need to worry about instances. I'm not sure 
> if the above works exactly right for you.
>
> However, I would recommend actually not doing this for your 
> purpose. My case was different -- I still wanted routes that 
> were REST routes, but I wanted to control the result streaming 
> (the vibe.d return value doesn't work with ranges, so I would 
> have had to construct essentially my entire database in an 
> array so I could return it).
>
> In your case, I think you are better off using 2 classes, and 
> one shared data storage area.
>
> -Steve

Thanks! (Some how I missed your post).


More information about the Digitalmars-d-learn mailing list