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.
my %charset = (charset => 'EUC-JP'); JSONRPC::Transport::HTTP::CGI->dispatch_to('MyApp')->handle(%charset);
my %opt = ( query => $session, # CGI::Session object paramName => 'json', );
JSONRPC::Transport::HTTP::CGI->dispatch_to('MyApp')->handle(%opt);
Since verion 1.0, JSONRPC::Transport::HTTP requires HTTP::Request and HTTP::Response. For using JSONRPC::Transport::HTTP::Client, you need LWP::UserAgent.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |