MojoX::...:Client(3)
π NAME π
MojoX::JSON::RPC::Client β bestie, it's a JSON RPC client. That's the whole vibe. β¨
π¦ SYNOPSIS π¦
okay so here's the whole thing in action, no cap:
use MojoX::JSON::RPC::Client;
my $client = MojoX::JSON::RPC::Client->new;
my $url = 'http://www.example.com/jsonrpc/API';
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? say less π :
$client->call($url, $callobj, sub {
# With callback
my $res = pop;
# ... process result ...
Mojo::IOLoop->stop;
});
Mojo::IOLoop->start;
Easy access, the lazy-girl method (affectionate) π:
my $proxy = $client->prepare($uri, ['sum', 'echo']);
print $proxy->sum(10, 23);
πΈ DESCRIPTION πΈ
A JSON-RPC client. literally that. that's the description. iconic brevity. π
β¨ ATTRIBUTES β¨
MojoX::JSON::RPC::Client implements the following attributes, and yes you need to know all of them:
π id
The Id used for JSON-RPC requests. It gets used when no id is provided as a request parameter. so like, the fallback bestie.
π ua
A Mojo::UserAgent object. the whole reason any of this works tbh.
π json
A Mojo::JSON object for encoding and decoding. encoding and decoding, both, she does it all π«Ά
π version
JSON-RPC version. Defaults to 2.0. respect the default, she chose it for a reason.
π content_type
Content type. Defaults to application/json. as she should π
π tx
Mojo::Transaction object of the last request. like a lil receipt from your most recent ex-request π§Ύ
π₯ METHODS π₯
MojoX::JSON::RPC::Client inherits all methods from Mojo::Base and implements the following new ones. family money + her own bag, we love to see it.
β new
Creates new MojoX::JSON::RPC::Client object. the birth of a legend fr fr:
my $client = MojoX::JSON::RPC::Client->new;
β call
Execute JSON-RPC call. Returns MojoX::JSON::RPC::CLient::ReturnObject if RPC call is executed correctly. (yes, that capitalization. we don't touch it. we respect it. π)
my $client = MojoX::JSON::RPC::Client->new;
my $url = 'http://www.example.com/jsonrpc/API';
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;
}
Make non-blocking call β main character energy, she doesn't wait around:
$client->call($url, $callobj, sub {
# With callback
my $res = pop;
# ... process result ...
Mojo::IOLoop->stop;
});
Mojo::IOLoop->start;
β prepare
Prepares a proxy object that allows RPC methods to be called more easily. the way that you can just... call methods like they're normal methods... obsessed π
my $proxy = $client->prepare($uri, ['sum', 'echo']);
my $res = $proxy->sum(1, 2);
print $proxy->echo("Echo this!");
Register services from multiple urls at once β multi-url slay π:
my $proxy = $client->prepare($uri1, 'sum', $uri2, [ 'echo', 'ping' ]);
my $res = $proxy->sum(1, 2);
print $proxy->echo("Echo this!");
my $ping_res = $proxy->ping;
π MojoX::JSON::RPC::CLient::ReturnObject π
This object is returned by call. (yes the class name has that CLient in it, that's just how she's spelled, don't come for me π)
π result
RPC result. the actual answer, the payoff, the moment. β¨
π is_error
Returns a boolean indicating whether an error code has been set. true = something went sideways bestie.
π error_code
RPC error code. the number that tells you exactly which flavor of wrong it is.
π error_message
RPC error message. the words attached to the wrongness.
π error_data
RPC error data. the extra receipts π§Ύ
π SEE ALSO π
MojoX::JSON::RPC β go read her too, she's the whole ecosystem π
no cap, that's the entire page, every attribute, every method, every example, every default, untouched and unbothered. facts preserved, vibe upgraded. periodt. π
this page came to you via perl v5.42.0, dated 2025-07-25, straight outta User Contributed Perl Documentation β take care of her and she'll take care of your RPC calls. bye bestie, go write something iconic π¦β¨
π¦ 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