• Home
  • History
  • Annotate
  • only in this directory
NameDateSize

..11-Apr-2013244

ChangesH A D20-Feb-20132.3 KiB

ex/H11-Apr-20138

lib/H11-Apr-20134

Makefile.PLH A D20-Feb-2013780

MANIFESTH A D20-Feb-2013434

META.ymlH A D20-Feb-2013666

READMEH A D20-Feb-20132.9 KiB

t/H11-Apr-20135

README

1JSON::RPC version 0.96
2=================
3NAME
4    JSON::RPC - Perl implementation of JSON-RPC 1.1 protocol
5
6DESCRIPTION
7     JSON-RPC is a stateless and light-weight remote procedure call (RPC)
8     protocol for inter-networking applications over HTTP. It uses JSON
9     as the data format for of all facets of a remote procedure call,
10     including all application data carried in parameters.
11
12    quoted from <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>.
13
14    This module was in JSON package on CPAN before. Now its interfaces was
15    completely changed.
16
17    The old modules - JSONRPC::Transport::HTTP and Apache::JSONRPC are
18    deprecated. Please try to use JSON::RPC::Server and JSON::RPC::Client
19    which support both JSON-RPC protocol version 1.1 and 1.0.
20
21EXAMPLES
22    CGI version.
23
24     #--------------------------
25     # In your application class
26     package MyApp;
27 
28     use base qw(JSON::RPC::Procedure); # Perl 5.6 or more than
29 
30     sub echo : Public {    # new version style. called by clients
31         # first argument is JSON::RPC::Server object.
32         return $_[1];
33     }
34 
35     sub sum : Public(a:num, b:num) { # sets value into object member a, b.
36         my ($s, $obj) = @_;
37         # return a scalar value or a hashref or an arryaref.
38         return $obj->{a} + $obj->{b};
39     }
40 
41     sub a_private_method : Private {
42         # ... can't be called by client
43     }
44 
45     sub sum_old_style {  # old version style. taken as Public
46         my ($s, @arg) = @_;
47        return $arg[0] + $arg[1];
48     }
49 
50     #--------------------------
51     # In your triger script.
52     use JSON::RPC::Server::CGI;
53     use MyApp;
54 
55     # simple
56      JSON::RPC::Server::CGI->dispatch('MyApp')->handle();
57 
58     # or 
59     JSON::RPC::Server::CGI->dispatch([qw/MyApp FooBar/])->handle();
60 
61     # or INFO_PATH version
62     JSON::RPC::Server::CGI->dispatch({'/Test' => 'MyApp'})->handle();
63 
64     #--------------------------
65     # Client
66     use JSON::RPC::Client;
67 
68     my $client = new JSON::RPC::Client;
69
70     my $uri = 'http://www.example.com/jsonrpc/Test';
71     my $obj = {
72        method  => 'sum', # or 'MyApp.sum'
73        params  => [10, 20],
74     };
75 
76     my $res = $client->call( $uri, $obj )
77 
78     if($res){
79        if ($res->is_error) {
80            print "Error : ", $res->error_message;
81        }
82        else {
83            print $res->result;
84        }
85     }
86     else {
87        print $client->status_line;
88     }
89 
90     # or
91 
92     $client->prepare($uri, ['sum', 'echo']);
93     print $client->sum(10, 23);
94 
95    See to JSON::RPC::Server::CGI, JSON::RPC::Server::Daemon,
96    JSON::RPC::Server::Apache2 JSON::RPC::Client and JSON::RPC::Procedure.
97
98ABOUT NEW VERSION
99    supports JSON-RPC protocol v1.1
100
101AUTHOR
102    Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
103
104COPYRIGHT AND LICENSE
105    Copyright 2007-2008 by Makamaka Hannyaharamitu
106
107    This library is free software; you can redistribute it and/or modify it
108    under the same terms as Perl itself.
109