NAME

JSON::RPC::Client - Perl implementation of JSON-RPC client

SYNOPSIS

use JSON::RPC::Client;

my $client = new JSON::RPC::Client;
my $url    = 'http://www.example.com/jsonrpc/API';

my $callobj = {
   method  => 'sum',
   params  => [ 17, 25 ], # ex.) params => { a => 20, b => 10 } for JSON-RPC v1.1
};

my $res = $client->call($uri, $callobj);

if($res) {
   if ($res->is_error) {
       print "Error : ", $res->error_message;
   }
   else {
       print $res->result;
   }
}
else {
   print $client->status_line;
}


$client->prepare($uri, ['sum', 'echo']);
print $client->sum(10, 23);

DESCRIPTION

This is JSON-RPC Client. See http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html.

Gets perl object and convert to JSON data.

Sends request.

Gets response.

Converts JSON data to perl object.

JSON::RPC::Client

METHODS

new

Creates new JSON::RPC::Client object.

call($uri, $procedure_object)

Requests to $uri with $procedure_object. Reuest method is usually 'post'. If $uri has query string, method is 'get'.

About 'GET' method, see to http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#GetProcedureCall.

Return value is "JSON::RPC::ReturnObject".

prepare($uri, $arrayref_of_procedure)

Allow to call methods in contents of $arrayref_of_procedure. Return value is a result part of JSON::RPC::ReturnObject.

$client->prepare($uri, ['sum', 'echo']);
my $res = $client->echo('foobar'); # $res is 'foobar'.

Currently, can't call method name same as built-in method.

version

Sets JSON-RPC protocol version. 1.1 by default.

id

Sets a request identifier. In JSON-RPC 1.1, it is optoinal.

If you set version 1.0 and don't set id, the module sets 'JSON::RPC::Client'.

ua

Setter/getter to LWP::UserAgent object.

json

Setter/getter to JSON coder object. Default is JSON::PP, likes this:

$self->json( JSON::PP->new->allow_nonref->utf8 );
status_line

Returns status code; After call remote procedure, a status code is set.

JSON::RPC::ReturnObject

METHODS

is_success
is_error
error_message
result
content
jsontext
version

JSON::RPC::ServiceObject

RESERVED PROCEDURE

When a client call a procedure (method) name 'system.foobar', JSON::RPC::Server look up MyApp::system::foobar.

http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ProcedureCall

http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ServiceDescription

There is JSON::RPC::Server::system::describe for default response of 'system.describe'.

SEE ALSO

http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html

http://json-rpc.org/wiki/specification

AUTHOR

Makamaka Hannyaharamitu, <makamaka[at]cpan.org>

COPYRIGHT AND LICENSE

Copyright 2007 by Makamaka Hannyaharamitu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.