JSONRPC::Transport::HTTP(3)

NAME
JSONRPC::Transport::HTTP

SYNOPSIS
 #--------------------------
 # 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.

DESCRIPTION
This module is JSONRPC subclass. Most ideas were borrowed from XMLRPC::Lite. Currently "JSONRPC" provides only CGI server function.

CHARSET
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);

QUERY OBJECT
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);

CAUTION
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 HTTP::Request and HTTP::Response. For using JSONRPC::Transport::HTTP::Client, you need LWP::UserAgent.

SEE ALSO
JSONRPC JSON XMLRPC::Lite <http://json-rpc.org/>

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

COPYRIGHT AND LICENSE
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.