JRPC
view release on metacpan or search on metacpan
JRPC/Client.pm view on Meta::CPAN
=head1 NAME
JRPC::Client - JSON-RPC 2.0 Client
=head1 SYNOPSIS
use JRPC::Client;
my $client = JRPC::Client->new();
$req = $client->new_request("http://jservices.com/WorldTime");
my $resp = $req->call('Timeinfo.getlocaltime', {'tzname' => 'CET', 'clockhrs' => '24'});
if (my $err = $resp->error()) { die("$err->{'message'}"); }
my $res = $resp->result();
print("Local time in CET is: $res->{'timeiso'}\n");
=head1 DESCRIPTION
JRPC::Client is a Perl LWP based JSON-RPC 2.0 Client hoping to minimize tedious boilerplate code for JSON-RPC
interaction, yet enabling advanced use cases by the power of LWP / HTTP::Request.
JRPC::Client complies to conventions of JSON-RPC 2.0, but it can be coerced to be used for other versions as well.
=head2 $client = JRPC::Client->new()
bin/jrpc_client.pl view on Meta::CPAN
#my $cbport = $servport + 10;
if ($ENV{'JRPC_DEBUG'}) {$JRPC::Client::Request::debug = 1;}
my $client = JRPC::Client->new();
#my $meth = 'LongSearch.searchpath';
#my $params = {'path' => "/etc", 'cburl' => "http://localhost:$cbport/"};
###### Main flow ########
my $req = $client->new_request($para{'url'});
my $resp = $req->call($para{'method'}, $jparams);
if (my $err = $resp->error()) { die("JSON-RPC Error: $err->{'message'} ($err->{'code'})"); }
my $res = $resp->result();
#print("Local time in CET is: $res->{'timeiso'}\n");
print("Sync result: ".Dumper($res));
# TODO: If async processing takes place in server end, wait here...
if ($para{'async'}) {
#eval("use ");
# Spawn waiting server
}
examples/filesearch.pl view on Meta::CPAN
my $cbport = $servport + 10;
if ($ENV{'JRPC_DEBUG'}) {$JRPC::Client::Request::debug = 1;}
my $client = JRPC::Client->new();
my $meth = 'LongSearch.searchpath';
my $params = {'path' => "/etc", 'cburl' => "http://localhost:$cbport/"};
###### Main flow ########
$req = $client->new_request("http://localhost:$servport/");
my $resp = $req->call($meth, $params);
if (my $err = $resp->error()) { die($err->{'message'}); }
my $res = $resp->result();
#print("Local time in CET is: $res->{'timeiso'}\n");
print("Sync result: ".Dumper($res));
sub createcbserver {
my ($foo) = @_;
print("Spawning Callback Server thread on $cbport. Waiting ...\n");
CBServer->new($cbport)->run();
}
my $thr = threads->create('createcbserver', ); # 'argument'
# Block and wait response
( run in 0.594 second using v1.01-cache-2.11-cpan-49f99fa48dc )