Thread overview | |||||
---|---|---|---|---|---|
|
March 12, 2008 AJAX+JSON RPC | ||||
---|---|---|---|---|
| ||||
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"}`. |
March 13, 2008 Re: AJAX+JSON RPC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Moritz Warning | 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>
|
March 13, 2008 Re: AJAX+JSON RPC | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | 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.
|
Copyright © 1999-2021 by the D Language Foundation