1JSON::RPC::Legacy(3)  User Contributed Perl Documentation JSON::RPC::Legacy(3)
2
3
4

NAME

6       JSON::RPC - Perl implementation of JSON-RPC 1.1 protocol
7

DESCRIPTION

9        JSON-RPC is a stateless and light-weight remote procedure call (RPC)
10        protocol for inter-networking applications over HTTP. It uses JSON
11        as the data format for of all facets of a remote procedure call,
12        including all application data carried in parameters.
13
14       quoted from <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>.
15
16       This module was in JSON package on CPAN before.  Now its interfaces was
17       completely changed.
18
19       The old modules - JSONRPC::Transport::HTTP and Apache::JSONRPC are
20       deprecated.  Please try to use JSON::RPC::Server and JSON::RPC::Client
21       which support both JSON-RPC protocol version 1.1 and 1.0.
22

EXAMPLES

24       CGI version.
25
26        #--------------------------
27        # In your application class
28        package MyApp;
29
30        use base qw(JSON::RPC::Procedure); # Perl 5.6 or more than
31
32        sub echo : Public {    # new version style. called by clients
33            # first argument is JSON::RPC::Server object.
34            return $_[1];
35        }
36
37
38        sub sum : Public(a:num, b:num) { # sets value into object member a, b.
39            my ($s, $obj) = @_;
40            # return a scalar value or a hashref or an arryaref.
41            return $obj->{a} + $obj->{b};
42        }
43
44
45        sub a_private_method : Private {
46            # ... can't be called by client
47        }
48
49
50        sub sum_old_style {  # old version style. taken as Public
51            my ($s, @arg) = @_;
52           return $arg[0] + $arg[1];
53        }
54
55
56        #--------------------------
57        # In your triger script.
58        use JSON::RPC::Server::CGI;
59        use MyApp;
60
61        # simple
62         JSON::RPC::Server::CGI->dispatch('MyApp')->handle();
63
64        # or
65        JSON::RPC::Server::CGI->dispatch([qw/MyApp FooBar/])->handle();
66
67        # or INFO_PATH version
68        JSON::RPC::Server::CGI->dispatch({'/Test' => 'MyApp'})->handle();
69
70        #--------------------------
71        # Client
72        use JSON::RPC::Client;
73
74        my $client = new JSON::RPC::Client;
75
76        my $uri = 'http://www.example.com/jsonrpc/Test';
77        my $obj = {
78           method  => 'sum', # or 'MyApp.sum'
79           params  => [10, 20],
80        };
81
82        my $res = $client->call( $uri, $obj )
83
84        if($res){
85           if ($res->is_error) {
86               print "Error : ", $res->error_message;
87           }
88           else {
89               print $res->result;
90           }
91        }
92        else {
93           print $client->status_line;
94        }
95
96        # or
97
98        $client->prepare($uri, ['sum', 'echo']);
99        print $client->sum(10, 23);
100
101       See to JSON::RPC::Server::CGI, JSON::RPC::Server::Daemon,
102       JSON::RPC::Server::Apache JSON::RPC::Client and JSON::RPC::Procedure.
103

ABOUT NEW VERSION

105       supports JSON-RPC protocol v1.1
106

TODO

108       Document
109       Examples
110       More Tests
111

AUTHOR

113       Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
114
116       Copyright 2007-2008 by Makamaka Hannyaharamitu
117
118       This library is free software; you can redistribute it and/or modify it
119       under the same terms as Perl itself.
120
121
122
123perl v5.34.0                      2022-01-21              JSON::RPC::Legacy(3)
Impressum