www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - AJAX+JSON RPC

reply Moritz Warning <moritzwarning _nospam_web.de> writes:
I thought some might be interested in a flexible JSON RPC
(AJAX with JSON instead of XML).

http://web-gmui.svn.sourceforge.net/viewvc/web-gmui/trunk/json/JsonCore.d?
revision=201&view=markup

class Foo
{
   Foo[] getFoos() { return [new Foo, new Foo]; }

   char[] getName() { return "myname"; }

   uint getId(uint i) { return i; }

   void advanced(char[] a, char[] b) {}
}

void main(char[][] args)
{
   //don't need to be called, only instantiated.
   add!("Foo.getId");
   add!("Foo.getName", "name"); //we set an optional alias
   add!("Foo.getFoos");
   add!("Foo.advanced");

   Foo foo = new Foo;

   //the string we could get from some client side JavaScript
   char[] input = "getFoos{getId(13),name}";

   //the actual parsing
   char[] output = Parse!(Foo).parse(o, foo, input);

  /*output is now
  * `{0 : {getId : 13, name : "myname"}, 1 : { getId : 13, name : 
"myname"}}`);
   */
}

The call Syntax is not JSON compatible, but the returned data is.
add! accepts functions, class methods and global variables.
An optional alias can also be set.
You can call functions/methods with strings and numbers and arrays of 
those.
Some examples:


`getFoos[getId(13),name]`
=>
`[{getId : 13, name : "myname"}, { getId : 13, name : "myname"}]`.


`advanced("x","y"),name()bar`
=>
`{advanced: null, bar : "myname"}`.
Mar 12 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Moritz,

 I thought some might be interested in a flexible JSON RPC (AJAX with
 JSON instead of XML).
 
Umm. What a strange coincidence. Two different AJAX + D template libs in 5 hours. It looks like yours is a bit older than mine as mine was started only about 100 hours ago. and from the looks of it they might (tango v. phobos aside) be complementary. (I'm not exactly clear on what yours does) <G>
Mar 12 2008
parent Moritz Warning <moritzwarning _nospam_web.de> writes:
On Thu, 13 Mar 2008 01:35:09 +0000, BCS wrote:

 Reply to Moritz,
 
 I thought some might be interested in a flexible JSON RPC (AJAX with
 JSON instead of XML).
 
 
Umm. What a strange coincidence. Two different AJAX + D template libs in 5 hours. It looks like yours is a bit older than mine as mine was started only about 100 hours ago. and from the looks of it they might (tango v. phobos aside) be complementary. (I'm not exactly clear on what yours does) <G>
Actually, when I saw your announcement I thought it would be a nice idea to post my stuff as well. So people can also go with JSON. *g* It's just an RPC interface. You put in a string saying "call this and that function" and it returns a JSON structured string with the returned values in it.
Mar 12 2008