arsd users: weigh in on proposed breaking change

Adam D Ruppe destructionator at gmail.com
Mon Dec 19 21:41:47 UTC 2022


On Monday, 19 December 2022 at 16:03:36 UTC, bachmeier wrote:
> What you're proposing barely qualifies as breakage.

Yeah, and the dub users wouldn't even notice it since I'll just 
add another 50 lines to dub.json for them. (Though they will be 
the ones to see the version number update. I tell people to use 
 >= instead of ~> like dub suggests since what I consider a 
breaking change is almost certainly not going to affect them, but 
since ~> is the default they might be trapped on an old version 
for some time. oh well)

> The entire thing is this 25-line file:

Oh yes, I remember this. It is a cute little program.

> From time to time I'll add a web interface on localhost to a D 
> utility I've written. That sort of thing.

Little web interfaces are actually not half bad for a lot of 
things. You might enjoy experimenting with that cgi dispatcher 
some day, with its `serveApi` function it can auto-generate html 
forms form D functions. I haven't written much documentation of 
this stuff yet though.

But check it out:

---
import arsd.cgi;

class TheClass : WebObject {
         @UrlName("") // indicate this is the root function
         string hello(string name) {
                 return "Hello, " ~ name ~ "!";
         }

         static struct Info {
                 string name;
                 string title;
         }

         @AutomaticForm
         @(Cgi.RequestMethod.POST)
         Info[] withAutomaticForm(Info[] info) {
                 return info;
         }
}

mixin DispatcherMain!(
         "/".serveApi!TheClass
);
---

For this one, you will want to compile with `dmd -i` with the 
arsd repo cloned locally, since it requires cgi.d, dom.d, and 
jsvar.d. Of course, you can just download them and build with the 
explicit list too.

Relatively slow build for an arsd module, about 1.6s for this 
example on my computer, but I've still kept it kinda under 
control despite the code gen magic it is doing behind the scenes.

But anyway, run it! Here, I put a binary up so you can try 
yourself:

http://arsdnet.net/cgi-bin/ncgi3/?name=D+fan

http://arsdnet.net/cgi-bin/ncgi3/with-automatic-form

You can see how it builds the form and some data output all from 
the D struct and function definitions. Not ideal for user-facing 
stuff (that's where you get into all the other code like custom 
presenter classes or the arsd.webtemplate module etc), but if you 
want a quick ui to call some things i quite like what it does 
automatically.

And of course it can do the json output too:

http://arsdnet.net/cgi-bin/ncgi3/?name=D+fan&format=json


More information about the Digitalmars-d mailing list