1JSON::RPC::Legacy::ClieUnste(r3)Contributed Perl DocumenJtSaOtNi:o:nRPC::Legacy::Client(3)
2
3
4
6 JSON::RPC::Legacy::Client - Perl implementation of JSON-RPC client
7
9 use JSON::RPC::Legacy::Client;
10
11 my $client = new JSON::RPC::Legacy::Client;
12 my $url = 'http://www.example.com/jsonrpc/API';
13
14 my $callobj = {
15 method => 'sum',
16 params => [ 17, 25 ], # ex.) params => { a => 20, b => 10 } for JSON-RPC v1.1
17 };
18
19 my $res = $client->call($uri, $callobj);
20
21 if($res) {
22 if ($res->is_error) {
23 print "Error : ", $res->error_message;
24 }
25 else {
26 print $res->result;
27 }
28 }
29 else {
30 print $client->status_line;
31 }
32
33
34 # Easy access
35
36 $client->prepare($uri, ['sum', 'echo']);
37 print $client->sum(10, 23);
38
40 This is JSON-RPC Client. See
41 <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>.
42
43 Gets a perl object and convert to a JSON request data.
44
45 Sends the request to a server.
46
47 Gets a response returned by the server.
48
49 Converts the JSON response data to the perl object.
50
52 METHODS
53 $client = JSON::RPC::Legacy::Client->new
54 Creates new JSON::RPC::Legacy::Client object.
55
56 $response = $client->call($uri, $procedure_object)
57 Calls to $uri with $procedure_object. The request method is
58 usually "POST". If $uri has query string, method is "GET".
59
60 About 'GET' method, see to
61 <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#GetProcedureCall>.
62
63 Return value is "JSON::RPC::Legacy::ReturnObject".
64
65 $client->prepare($uri, $arrayref_of_procedure)
66 Allow to call methods in contents of $arrayref_of_procedure. Then
67 you can call the prepared methods with an array reference or a
68 list.
69
70 The return value is a result part of
71 JSON::RPC::Legacy::ReturnObject.
72
73 $client->prepare($uri, ['sum', 'echo']);
74
75 $res = $client->echo('foobar'); # $res is 'foobar'.
76
77 $res = $client->sum(10, 20); # sum up
78 $res = $client->sum( [10, 20] ); # same as above
79
80 If you call a method which is not prepared, it will "croak".
81
82 Currently, can't call any method names as same as built-in methods.
83
84 version
85 Sets the JSON-RPC protocol version. 1.1 by default.
86
87 id Sets a request identifier. In JSON-RPC 1.1, it is optional.
88
89 If you set "version" 1.0 and don't set id, the module sets
90 'JSON::RPC::Legacy::Client' to it.
91
92 ua Setter/getter to LWP::UserAgent object.
93
94 json
95 Setter/getter to the JSON coder object. Default is JSON, likes
96 this:
97
98 $self->json( JSON->new->allow_nonref->utf8 );
99
100 $json = $self->json;
101
102 This object serializes/deserializes JSON data. By default,
103 returned JSON data assumes UTF-8 encoded.
104
105 status_line
106 Returns status code; After "call" a remote procedure, the status
107 code is set.
108
109 create_json_coder
110 (Class method) Returns a JSON de/encoder in "new". You can
111 override it to use your favorite JSON de/encoder.
112
114 "call" method or the methods set by "prepared" returns this object.
115 (The returned JSON data is decoded by the JSON coder object which was
116 passed by the client object.)
117
118 METHODS
119 is_success
120 If the call is successful, returns a true, otherwise a false.
121
122 is_error
123 If the call is not successful, returns a true, otherwise a false.
124
125 error_message
126 If the response contains an error message, returns it.
127
128 result
129 Returns the result part of a data structure returned by the called
130 server.
131
132 content
133 Returns the whole data structure returned by the called server.
134
135 jsontext
136 Returns the row JSON data.
137
138 version
139 Returns the version of this response data.
140
143 When a client call a procedure (method) name 'system.foobar',
144 JSON::RPC::Legacy::Server look up MyApp::system::foobar.
145
146 <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ProcedureCall>
147
148 <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ServiceDescription>
149
150 There is JSON::RPC::Legacy::Server::system::describe for default
151 response of 'system.describe'.
152
154 <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>
155
156 <http://json-rpc.org/wiki/specification>
157
159 Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
160
162 Copyright 2007-2008 by Makamaka Hannyaharamitu
163
164 This library is free software; you can redistribute it and/or modify it
165 under the same terms as Perl itself.
166
167
168
169perl v5.32.0 2020-07-28 JSON::RPC::Legacy::Client(3)