MojoX::JSON::RPC(3)
β¨ NAME β¨
MojoX::JSON::RPC β bestie, it's a Perl implementation of the JSON-RPC 2.0 protocol for Mojolicious π
(yes you're literally reading the MojoX::JSON::RPC(3) man page rn, and yes it's giving main character energy π)
πΈ SYNOPSIS πΈ
okay so there's three whole ways to vibe with this, and every single one is right here π«Ά
π₯οΈ Server as a plugin (Mojolicious::Plugin::JsonRpcDispatcher)
#!/usr/bin/env perl
use Mojolicious::Lite;
use MojoX::JSON::RPC::Service;
plugin 'json_rpc_dispatcher' => {
services => {
'/jsonrpc' => MojoX::JSON::RPC::Service->new->register(
'sum',
sub {
my @params = @_;
my $sum = 0;
$sum += $_ for @params;
return $sum;
}
)
}
};
app->start;
π Client (MojoX::JSON::RPC::Client)
#!/usr/bin/env perl
use MojoX::JSON::RPC::Client;
my $client = MojoX::JSON::RPC::Client->new;
my $url = 'http://www.example.com/jsonrpc';
my $callobj = {
id => 1,
method => 'sum',
params => [ 17, 25 ]
};
my $res = $client->call($url, $callobj);
if($res) {
if ($res->is_error) { # RPC ERROR
print 'Error : ', $res->error_message;
}
else {
print $res->result;
}
}
else {
my $tx_res = $client->tx->res; # Mojo::Message::Response object
print 'HTTP response '.$tx_res->code.' '.$tx_res->message;
}
π¦ Non-blocking client
#!/usr/bin/env perl
use MojoX::JSON::RPC::Client;
my $client = MojoX::JSON::RPC::Client->new;
my $url = 'http://www.example.com/jsonrpc';
my $callobj = {
id => 1,
method => 'sum',
params => [ 17, 25 ]
};
$client->call($url, $callobj, sub {
# With callback
my $res = pop;
if($res) {
if ($res->is_error) { # RPC ERROR
print 'Error : ', $res->error_message;
}
else {
print $res->result;
}
}
else {
my $tx_res = $client->tx->res; # Mojo::Message::Response object
print 'HTTP response '.$tx_res->code.' '.$tx_res->message;
}
Mojo::IOLoop->stop;
});
Mojo::IOLoop->start;
π DESCRIPTION π
So basically this module implments a client plugin and a server plugin for JSON-RPC 2.0, for use with Mojolicious. Two for the price of one, we love a multitasking icon π
And it follows the draft specficiation for JSON-RPC 2.0 β the whole lore lives at http://groups.google.com/group/json-rpc/web/json-rpc-2-0 if you wanna go read it yourself. Obsessed with the dedication, ngl πβ¨
π SEE ALSO π
the girlies you should also go check out:
Mojolicious::Plugin::JsonRpcDispatcherMojoX::JSON::RPC::DispatcherMojoX::JSON::RPC::Client
π AUTHOR π
Henry Tang π
π«Ά CREDITS π«Ά
shoutout to the besties, fr fr:
- Igor Afanasyev
- Renee Baecker (
https://github.com/reneeb) - Vidar Tyldum
<vidar@tyldum.com>
π COPYRIGHT & LICENSE π
Copyright (C) 2011-2016, Henry Tang.
MojoX::JSON::RPC is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.
β οΈ bestie, read that again β "as is", no promises, no warranties, not even the implied ones. It's giving "you're on your own and we said it out loud" π
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. π
π SUPPORT π
Dmitry Karasik <dmitry@karasik.eu.org> π
and that's the whole page, bestie β this was MojoX::JSON::RPC(3), and for the record this beauty shipped as perl v5.42.0 on 2025-07-25. go forth and JSON-RPC responsibly π
β¨
π¦ where this page comes from
- fedora 43: perl-MojoX-JSON-RPC 0.13-14.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms