| /usr/local/perl/lib/site_perl/5.8.5/JSONRPC/Transport/HTTP.pm |
JSONRPC::Transport::HTTP
#-------------------------- # In your application class package MyApp;
sub own_method { # called by clients
my ($server, @params) = @_; # $server is JSONRPC object.
...
# return a scalar value or a hashref or an arryaref.
}
#--------------------------
# In your main cgi script.
use JSONRPC::Transport::HTTP;
use MyApp;
# a la XMLRPC::Lite
JSONRPC::Transport::HTTP::CGI->dispatch_to('MyApp')->handle();
################## # Daemon version # ##################
use strict;
use lib qw(. ./lib);
use JSONRPC::Transport::HTTP;
my $daemon = JSONRPC::Transport::HTTP::Daemon
->new(LocalPort => 8080)
->dispatch_to('MyApp/Test', 'MyApp/Test2');
$daemon->handle();
################## # Apache version # ##################
http.conf or .htaccess
SetHandler perl-script PerlHandler Apache::JSONRPC PerlModule MyApp::Test PerlSetVar dispatch_to "MyApp::Test, MyApp/Test2/"
#-------------------------- # Client #--------------------------
use JSONRPC::Transport::HTTP; my $uri = 'http://www.example.com/MyApp/Test/';
my $res = JSONRPC::Transport::HTTP
->proxy($uri)
->call('echo',['This is test.'])
->result;
if($res->error){
print $res->error,"\n";
}
else{
print $res->result,"\n";
}
# or
my $client = JSONRPC::Transport::HTTP->proxy($uri);
print $client->echo('This is test.'); # the alias, _echo is same.
In the next large update version, JSON and JSONRPC modules are split.
JSONRPC* and Apache::JSONRPC are deleted from JSON dist. JSONRPC::Client, JSONRPC::Server and JSONRPC::Procedure in JSON::RPC dist.
Modules in JSON::RPC dist supports JSONRPC protocol v1.1 and 1.0.
This module is JSONRPC subclass.
Most ideas were borrowed from the XMLRPC::Lite manpage.
Currently JSONRPC provides only CGI server function.
When the module returns response, its charset is UTF-8 by default. You can change it via passing a key/value pair into handle().
my %charset = (charset => 'EUC-JP');
JSONRPC::Transport::HTTP::CGI->dispatch_to('MyApp')->handle(%charset);
If you want to use any other query object instead of CGI
for JSONRPC::Transport::HTTP::CGI, you can pass query option and
paramName.
my %opt = ( query => $session, # CGI::Session object paramName => 'json', );
JSONRPC::Transport::HTTP::CGI->dispatch_to('MyApp')->handle(%opt);
JSONRPC::Transport::HTTP::CGI requires CGI.pm which version is more than 2.9.2. (the core module in Perl 5.8.1.)
Since verion 1.0, JSONRPC::Transport::HTTP requires the HTTP::Request manpage and the HTTP::Response manpage. For using JSONRPC::Transport::HTTP::Client, you need the LWP::UserAgent manpage.
JSONRPC JSON the XMLRPC::Lite manpage http://json-rpc.org/
Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
Copyright 2005 by Makamaka Hannyaharamitu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| /usr/local/perl/lib/site_perl/5.8.5/JSONRPC/Transport/HTTP.pm |