Introducing JSON::RPC::Dispatcher

Have you ever needed to create an application server quickly? Maybe you tried SOAP? It's never a fun experience, and if you're like me you may have ended up reinventing the wheel a lot due to poor quality modules on CPAN, or confusing documentation. Today I'm announcing JSON::RPC::Dispatcher. It's a super easy way to create JSON RPC 2.0 web services. It's built on top of Plack so you can easily deploy it anywhere you need.

How easy is it to create an app server? This easy:

use JSON::RPC::Dispatcher;

my $rpc = JSON::RPC::Dispatcher->new;

sub add_em {
my @params = @_;
my $sum = 0;
$sum += $_ for @params;
return $sum;
}
$rpc->register( 'sum', \&add_em );

$rpc->to_app;

Voila, you've just exposed a subroutine to the network. You can then request it via a simple JSON post or get operation.

{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}

But that's just basic. It also has JSON::RPC::Dispatcher::App, which allows you to create an object oriented app server in the same number of lines of code. And since it's built on top of the JSON-RPC 2.0 standard, you can interact with it using any of the numerous JSON-RPC 2.0 clients available for dozens of different languages out there, including Perl!

3 Comments

As far as I've seen, JSORB is currently used primarily in KiokuDB::Navigator.


It provides introspection into Moose objects and automating stuff like that, which you obviously, don't really want/care/need to implement in yours.


Yours seems like a more concise and generic JSON::RPC implementation which is unique and.. well, awesome! :)

Leave a comment

About JT Smith

user-pic My little part in the greater Perl world.