A little of coordination for Rosettacode
Adam D. Ruppe
destructionator at gmail.com
Fri Jun 14 15:32:47 PDT 2013
On Friday, 14 June 2013 at 22:17:16 UTC, bearophile wrote:
> http://rosettacode.org/wiki/Distributed_programming#D
It kinda sounds like the description calls for something like
what web.d does:
server:
import arsd.web;
class Foo : ApiProvider {
export string hello(string name) { return "hello, " ~ name; }
export int add(int a, int b) { return a + b; }
}
mixin FancyMain!Foo;
client:
import arsd.curl;
import std.stdio;
void main() {
writeln(curl("http://example.com/server/hello?name=me"));
}
or javascript client:
Foo.hello("me").get(alert); // will pop up "hello, me"
or php client:
$api = new Foo("http://example.com/server/");
echo $api->add(10, 20)->getSync(); // prints 30
(the code for this is generated automatically by web.d. I also
wrote a bash [!] script to call arbitrary web.d functions
remotely but have not actually done the same for D itself yet!
The reason is for all my use cases, I can just call the D
function without going through the http middle man because all
the D is part of the same executable program. Interestingly, the
D one would probably use a code generator like javascript rather
than opDispatch like the bash and php examples do because the
code generator could give more type safety.)
This is a generic protocol, can handle many things at once, and
uses pretty natural data structures. (The returned values can be
almost anything, but the arguments must be all types that can be
converted from strings or arrays of strings.)
This actual example here uses several thousand lines of library
code but if you think it would fit the description, I'm sure I
can do a basic demo in far fewer lines using nothing but phobos.
More information about the Digitalmars-d-learn
mailing list