[ANN] Orbjson, a JSON-RPC ORB for JavaScript/Ruby interaction

An initial gem release of Ruby Orbjson is available. It provides an ORB (object request broker) for facilitating JavaScript/Ruby interaction using JSON-RPC.

On the server, services are registered with Orbjson using Needle. The library provides libs for CGI or WEBrick handlers to process JSON-RPC calls (such as might be sent from a Web browser using the XmlHttpRequest object).

Orbjson converts the JSON message to a Ruby object (thanks to Florian Frank's code) and locates the appropriate class via Needle (thanks, Jamis). The method invocation results are serialized to JSON and sent back to the client.

The gem depends on Jamis Buck's Needle, which rubygems should automagically download if you do not have it, and Florian's gem for ruby-json, which I believe is only hosted on sourceforge. You will have to install that yourself, as I do not think there is anyway to automate this.

There are examples in the 'examples/' dir. You can also run either

   orbjson create-cgi <dirpath>

or

   orbjson create-webrick <dirpath>

to create skeleton code (vielen dank to Michael Neummann; I pilfered his Wee code-creator source for this part).

The example client page use the jsonrpc.js script from Jan-Klaas Kollhof and Michael Clark, which is based on Jan-Klaas' JavaScript o lait library (jsolait). I'm not entirely happy with that code (I'd consider some different design choices for more fluid JavaScript client behavior), but it's good and it works.

This is a work in progress. It's pretty straightforward, though.

Comments and patches welcome. Give it a whirl, see what breaks.

I'll release a tar/zip version when I get around to assembling an install.rb file; making a gem is so much easier.

Download:
   http://rubyforge.org/projects/orbjson/

or
   gem install orbjson

ruby-json:
   http://cvs.sourceforge.net/viewcvs.py/json/ruby-json/

JSON (JavaScript Object Notation):
   http://www.crockford.com/JSON/

JSON-RPC is like XML-RPC, but with, um, JSON:
   http://www.json-rpc.org/

The jsonrpc.js file was snarfed from a Java project:
   http://oss.metaparadigm.com/jsonrpc/

James Britt

An initial gem release of Ruby Orbjson is available. It provides an ORB
(object request broker) for facilitating JavaScript/Ruby interaction
using JSON-RPC.

Nice work, James! I'm anxious to try this out.

- Jamis

···

On 14:01 Mon 28 Feb , James Britt wrote:

On the server, services are registered with Orbjson using Needle. The
library provides libs for CGI or WEBrick handlers to process JSON-RPC
calls (such as might be sent from a Web browser using the XmlHttpRequest
object).

Orbjson converts the JSON message to a Ruby object (thanks to Florian
Frank's code) and locates the appropriate class via Needle (thanks,
Jamis). The method invocation results are serialized to JSON and sent
back to the client.

The gem depends on Jamis Buck's Needle, which rubygems should
automagically download if you do not have it, and Florian's gem for
ruby-json, which I believe is only hosted on sourceforge. You will have
to install that yourself, as I do not think there is anyway to automate
this.

There are examples in the 'examples/' dir. You can also run either

  orbjson create-cgi <dirpath>

or

  orbjson create-webrick <dirpath>

to create skeleton code (vielen dank to Michael Neummann; I pilfered his
Wee code-creator source for this part).

The example client page use the jsonrpc.js script from Jan-Klaas Kollhof
and Michael Clark, which is based on Jan-Klaas' JavaScript o lait
library (jsolait). I'm not entirely happy with that code (I'd consider
some different design choices for more fluid JavaScript client
behavior), but it's good and it works.

This is a work in progress. It's pretty straightforward, though.

Comments and patches welcome. Give it a whirl, see what breaks.

I'll release a tar/zip version when I get around to assembling an
install.rb file; making a gem is so much easier.

Download:
  http://rubyforge.org/projects/orbjson/

or
  gem install orbjson

ruby-json:
  http://cvs.sourceforge.net/viewcvs.py/json/ruby-json/

JSON (JavaScript Object Notation):
  http://www.crockford.com/JSON/

JSON-RPC is like XML-RPC, but with, um, JSON:
  http://www.json-rpc.org/

The jsonrpc.js file was snarfed from a Java project:
  http://oss.metaparadigm.com/jsonrpc/

James Britt

--
Jamis Buck
jamis_buck@byu.edu
http://jamis.jamisbuck.org
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."

Thanks, James, this is awesome. I've been playing with it a bit today
(after getting past the packaging issues, which I know you're already
aware of) and have been quite impressed.

The one hangup I've seen is that the jsonrpc.js library you included
doesn't seem to allow for asynchronous requests. This limits a few
things (e.g. if the request has a delay in either transit or server
side processing, that delay still blocks the user, though nowhere near
as much as a full page refresh) but can be worked around by tweaking
the jsonrpc.js library.

I plan on looking into:

1) Finding and documenting the existing asynchronous capabilities of
jsonrpc.js, or
2) Adding asynchronous capabilities to jsonrpc.js

With asynchronous calls available this will be a perfect vehicle for
Ajax + Ruby!

Jacob Fugal

···

On Mon, 28 Feb 2005 14:01:01 +0900, James Britt <jamesUNDERBARb@neurogami.com> wrote:

An initial gem release of Ruby Orbjson is available. It provides an ORB
(object request broker) for facilitating JavaScript/Ruby interaction
using JSON-RPC.

On the server, services are registered with Orbjson using Needle. The
library provides libs for CGI or WEBrick handlers to process JSON-RPC
calls (such as might be sent from a Web browser using the XmlHttpRequest
object).

Orbjson converts the JSON message to a Ruby object (thanks to Florian
Frank's code) and locates the appropriate class via Needle (thanks,
Jamis). The method invocation results are serialized to JSON and sent
back to the client.

Jacob Fugal wrote:

... Thanks, James, this is awesome. I've been playing with it a bit today
(after getting past the packaging issues, which I know you're already
aware of) and have been quite impressed.

Thanks. I hope to have another version out tonight or tomorrow.

The one hangup I've seen is that the jsonrpc.js library you included
doesn't seem to allow for asynchronous requests. This limits a few
things (e.g. if the request has a delay in either transit or server
side processing, that delay still blocks the user, though nowhere near
as much as a full page refresh) but can be worked around by tweaking
the jsonrpc.js library.

Yes, the lack of async is a problem. The other thing I'm unhappy about is that the dynamically created client objects hang off the jsonrpc object. So, if the server expose foo.bar, the client needs to call jsonrpc.foo.bar, rather than simply foo.bar. But I see any reasons this has to be; after the initial call to listServices the client should be able to just build the corresponding client objects independently.

One thing that appealed to me about that particular jsonrpc script, though, was the idea that one could simply swap out server implementations with clients being none the wiser. And I somehow got the impression that this Java library JavaScript was following some sort of known convention. But that could be completely wrong. Might be worth seeing what people in PHP land do, for example, steal ideas from there, too.

Anyway, that part should be independent of the server code; one should be able to use any number of JavaScript client scripts (implementing json-rpc), all according to what works best for the application.

Thanks,

James

Thanks. I hope to have another version out tonight or tomorrow.

Great!

The other thing I'm unhappy about
is that the dynamically created client objects hang off the jsonrpc
object. So, if the server expose foo.bar, the client needs to call
jsonrpc.foo.bar, rather than simply foo.bar. But I see any reasons
this has to be; after the initial call to listServices the client should
be able to just build the corresponding client objects independently.

Even as such, you can capture the service (or I'm guessing you can, I
assume jsonrpc.service returns an object) in a variable to bypass the
jsonrpc object on future requests. E.g.

var calculator = jsonrpc.calculator;
calculator.compute( 1, 2 ); // => 3

Thanks again, James, for the package!

Jacob Fugal

···

On Tue, 1 Mar 2005 09:06:11 +0900, James Britt <jamesUNDERBARb@neurogami.com> wrote:

Well, it appears as if async operations have now been implemented (as well as HTTP authentication).

http://jsolait.net/examples/jsonrpc/jsolait/lib/jsonrpc.js

Seems to say it supports async stuff.

Anyway, great library. So easy to use too!

-Shalev

···

On Feb 28, 2005, at 7:06 PM, James Britt wrote:

Yes, the lack of async is a problem.
James

Shalev NessAiver wrote:

Well, it appears as if async operations have now been implemented (as well as HTTP authentication).

http://jsolait.net/examples/jsonrpc/jsolait/lib/jsonrpc.js

Seems to say it supports async stuff.

Figures. I just worked out a few bugs in my own async version.

Anyway, great library. So easy to use too!

Thanks (assuming you're referring to orbsjon : ) )

James