Pmrpc - JSON-RPC implementation in JavaScript using HTML5 postMessage API for transport

344 views
Skip to first unread message

Ivan Zuzak

unread,
Oct 4, 2009, 7:31:10 AM10/4/09
to JSON-RPC
Hi all,

First off a big salute everyone that's doing work on JSON-RPC - it's a
great effort and the spec is looking good so far.

I've seen several JSON-RPC implementations mentioned for client-server
and server-server communication (browsers being the clients), but
haven't seen anything for intra-browser communication. With the client-
side of web applications becoming more and more distributed to a set
of isolated components (widgets) there's also a need for mechanisms
that enable communication between these components. A lot of groups
and projects (OpenAjax, OpenSocial and Shindig, W3C widgets) are
poking at this problem on various levels, from low-level communication
primitives (postMessage, server-side proxied communication, cookies,
URL fragments) to high-level abstractions (messaging, rpc, pub-sub,
shared memory) and even new browser architectures (MS Gazelle and
Chromium).

What a colleague of mine and I have been working on is pmrpc - an open-
source JSON-RPC implementation in JavaScript using HTML5 postMessage
API for transport. The pmrpc library provides a simple API for
exposing and calling procedures from windows or iFrames on different
domains, and also provides several advanced features like callbacks,
ACL-based access control and automatic retries. For those who aren't
familiar with the postMessage API - it's an API introduced in HTML5
which enables windows and iframes within a browser to exchange
messages in a secure way (basically by sending messages and checking
from which domains these messages come from).

Pmrpc implements the JSON-RPC 2.0 spec in full (notifications, named
parameters, errors, etc), except for Batch calls since there is still
a lot of discussion going on about this feature. Nevertheless, we'd
like to see batch calls in pmrpc one day as well. Also, the JSON-RPC
implementation (JSON-RPC messages) is hidden behind a more user-
friendly API, but the API could have easily accepted JSON-RPC requests/
responses as parameters.

For more information please visit the project homepage -
http://code.google.com/p/pmrpc/ (there's a few notes on JSON-RPC
implementation in the API docs - http://code.google.com/p/pmrpc/wiki/PmrpcApiDocs#Implementation).
Feedback and discussions are appreciated. :)

Thanks,
Ivan

P.S Does anyone know what happened to JSON.com? I pinged Ric Johnson
(@openajax) but he's not answering.

Vladimir Dzhuvinov

unread,
Oct 5, 2009, 6:49:28 AM10/5/09
to JSON-RPC
Zdravo Ivane :)

I found postMessage() to be very useful in developing Mozilla XUL
apps.

It helped me in situations where I had to establish communication
between two or more open XUL windows.

It also proved valuable with large XUL apps. When a certain complexity
is reached, it makes a lot of sense to split a XUL window into several
iframes to improve modularity and make it easier to avoid XUL and JS
namespace clashes. I then used postMessage() to pass commands between
the various iframe-encapsulated window components. Simple and elegant.
It's only that I never thought of using JSON-RPC for this task. Next
time we get back to XUL programming I'll definitely look at your pmrpc
lib.

Vladimir Dzhuvinov

Matt (MPCM)

unread,
Oct 5, 2009, 7:01:30 AM10/5/09
to JSON-RPC
Excellent,

Glad to see json-rpc being used like this so early on in HTML5.
"Transports" that are interprocess/component do not get talked about
much, but it is one of the cleanest ways to use json-rpc. This looks
very interesting as an implementation, and I concur that this is going
to become *much* more relevant as things progress. Thank you for
contributing your efforts to the json-rpc space in this way!

Ric posted to the json group on Sept. 7th talking about issues he was
having with json.com, perhaps they are ongoing?

http://tech.groups.yahoo.com/group/json/message/1364

--
Matt (MPCM)

Ivan Zuzak

unread,
Oct 6, 2009, 2:55:21 AM10/6/09
to JSON-RPC
Pozdrav Vladimire :)

Using postMessage for XUL app development sounds very cool and
something I haven't even thought of! Are any of the apps you developed
open source so I can have a look? I've played with only basic XUL for
extending Firefox so I'm a bit rusty - did I understand correctly that
all XUL windows/iframes implement the postMessage API? Is this
something I shouldn't be surprised at - i.e. do XUL windows that are
not browser windows generally implement the same API as browser window
controls? Actually, this reminds me that in Chromium the postMesssage
API is used for extension development (for communication between
extensions and content webpage) - http://ajaxian.com/archives/chrome-extension-process-model-design-doc.

I'm very interested in finding *all* places where postMessage is or
could be used (e.g. inter-window communication, Web Workers, browser
extension development, XUL development) so that a one-size-fits-all
library can be developed that works in all of these cases. Any ideas
about other intra-browser communication possibilities?

Thanks!
Ivan

On Oct 5, 12:49 pm, Vladimir Dzhuvinov <vladimir.dzhuvi...@gmail.com>
wrote:

Ivan Zuzak

unread,
Oct 6, 2009, 3:26:49 AM10/6/09
to JSON-RPC
Hi Matt,

I couldn't agree with you more! JSON-RPC adoption is increasing nicely
for network transports (just a few weeks back I found out that
OpenSocial is using it) and I hope to see it adopted for various types
of intra-browser communication, as Vladimir pointed out.

Thanks for the feedback and the pointer to the Yahoo JSON group, I
wasn't even aware it existed :).

Cheers,
Ivan

Roy Ling

unread,
Aug 3, 2018, 8:35:07 AM8/3/18
to JSON-RPC
Hi Ivan,

This is a very interesting and helpful idea. Is the project active? do you move your project somewhere else after google code is closed?

Сёма Мрачный

unread,
Nov 8, 2018, 8:57:41 AM11/8/18
to JSON-RPC
hey Roy,

in case if you are still interesting — try https://github.com/izuzak/pmrpc

пятница, 3 августа 2018 г., 17:35:07 UTC+5 пользователь Roy Ling написал:
Reply all
Reply to author
Forward
0 new messages