1JSON::RPC::Legacy::ServUesre(r3)Contributed Perl DocumenJtSaOtNi:o:nRPC::Legacy::Server(3)
2
3
4

NAME

6       JSON::RPC::Server - Perl implementation of JSON-RPC sever
7

SYNOPSIS

9        # CGI version
10        use JSON::RPC::Legacy::Server::CGI;
11
12        my $server = JSON::RPC::Legacy::Server::CGI->new;
13
14        $server->dispatch_to('MyApp')->handle();
15
16
17
18        # Apache version
19        # In apache conf
20
21        PerlRequire /your/path/start.pl
22        PerlModule MyApp
23
24        <Location /jsonrpc/API>
25             SetHandler perl-script
26             PerlResponseHandler JSON::RPC::Legacy::Server::Apache
27             PerlSetVar dispatch "MyApp"
28             PerlSetVar return_die_message 0
29        </Location>
30
31
32
33        # Daemon version
34        use JSON::RPC::Legacy::Server::Daemon;
35
36        JSON::RPC::Legacy::Server::Daemon->new(LocalPort => 8080);
37                                 ->dispatch({'/jsonrpc/API' => 'MyApp'})
38                                 ->handle();
39
40
41
42        # FastCGI version
43        use JSON::RPC::Legacy::Server::FastCGI;
44
45        my $server = JSON::RPC::Legacy::Server::FastCGI->new;
46
47           $server->dispatch_to('MyApp')->handle();
48

DESCRIPTION

50       Gets a client request.
51
52       Parses its JSON data.
53
54       Passes the server object and the object decoded from the JSON data to
55       your procedure (method).
56
57       Takes your returned value (scalar or arrayref or hashref).
58
59       Sends a response.
60
61       Well, you write your procedure code only.
62

METHODS

64       new Creates new JSON::RPC::Legacy::Server object.
65
66       dispatch($package)
67       dispatch([$package1, $package1, ...])
68       dispatch({$path => $package, ...})
69           Sets your procedure module using package name list or arrayref or
70           hashref.  Hashref version is used for path_info access.
71
72       dispatch_to
73           An alias to "dispatch".
74
75       handle
76           Runs server object and returns a response.
77
78       raise_error(%hash)
79            return $server->raise_error(
80               code => 501,
81               message => "This is error in my procedure."
82            );
83
84           Sets an error.  An error code number in your procedure is an
85           integer between 501 and 899.
86
87       json
88           Setter/Getter to json encoder/decoder object.  The default value is
89           JSON object in the below way:
90
91            JSON->new->utf8
92
93           In your procedure, changes its behaviour.
94
95            $server->json->utf8(0);
96
97           The JSON coder creating method is  "create_json_coder".
98
99       version
100           Setter/Getter to JSON-RPC protocol version used by a client.  If
101           version is 1.1, returns 1.1. Otherwise returns 0.
102
103       charset
104           Setter/Getter to charset.  Default is 'UTF-8'.
105
106       content_type
107           Setter/Getter to content type.  Default is 'application/json'.
108
109       return_die_message
110           When your program dies in your procedure, sends a return object
111           with error message 'Procedure error' by default.
112
113           If this option is set, uses "die" message.
114
115            sub your_procedure {
116                my ($s) = @_;
117               $s->return_die_message(1);
118               die "This is test.";
119            }
120
121       retrieve_json_from_post
122           It is used by JSON::RPC::Legacy::Server subclass.
123
124       retrieve_json_from_get
125           In the protocol v1.1, 'GET' request method is also allowable.
126
127           It is used by JSON::RPC::Legacy::Server subclass.
128
129       response
130           It is used by JSON::RPC::Legacy::Server subclass.
131
132       request
133           Returns HTTP::Request object.
134
135       path_info
136           Returns PATH_INFO.
137
138       max_length
139           Returns max content-length to your application.
140
141       translate_error_message
142           Implemented in your subclass.  Three arguments (server object,
143           error code and error message) are passed.  It must return a
144           message.
145
146            sub translate_error_message {
147                my ($s, $code, $message) = @_;
148                return $translation_jp_message{$code};
149            }
150
151       create_json_coder
152           (Class method) Returns a JSON de/encoder in "new".  You can
153           override it to use your favorite JSON de/encode.
154

RESERVED PROCEDURE

156       When a client call a procedure (method) name 'system.foobar',
157       JSON::RPC::Legacy::Server look up MyApp::system::foobar.
158
159       <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ProcedureCall>
160
161       <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ServiceDescription>
162
163       There is JSON::RPC::Legacy::Server::system::describe for default
164       response of 'system.describe'.
165

SEE ALSO

167       JSON
168
169       <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>
170
171       <http://json-rpc.org/wiki/specification>
172

AUTHOR

174       Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
175
177       Copyright 2007-2008 by Makamaka Hannyaharamitu
178
179       This library is free software; you can redistribute it and/or modify it
180       under the same terms as Perl itself.
181
182
183
184perl v5.28.1                      2019-02-02      JSON::RPC::Legacy::Server(3)
Impressum