JSON::...:Client(3pm)

okay bestie, you're looking at the JSON::...:Client(3pm) page β€” yep, that’s the manual slot, and it lives under User Contributed Perl Documentation. It’s giving Perl JSON-RPC client realness, and we’re gonna go through every bit. πŸ’…

πŸ’– NAME πŸ’–

JSON::RPC::Legacy::Client β€” Perl implementation of JSON-RPC client. That’s the whole name vibe, bestie.

✨ SYNOPSIS ✨

okay so the quick-start looks like this, and yes, keep those variable names exactly as written:

use JSON::RPC::Legacy::Client;

my $client = new JSON::RPC::Legacy::Client;
my $url    = 'http://www.example.com/jsonrpc/API';

my $callobj = {
   method  => 'sum',
   params  => [ 17, 25 ], # ex.) params => { a => 20, b => 10 } for JSON-RPC v1.1
};

my $res = $client->call($uri, $callobj);

if($res) {
   if ($res->is_error) {
       print "Error : ", $res->error_message;
   }
   else {
       print $res->result;
   }
}
else {
   print $client->status_line;
}

# Easy access

$client->prepare($uri, ['sum', 'echo']);
print $client->sum(10, 23);

πŸ¦‹ DESCRIPTION πŸ¦‹

This is JSON-RPC Client. See <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>.

It gets a perl object and converts it to JSON request data.

It sends the request to a server.

It gets a response returned by the server.

It converts the JSON response data to the perl object.

πŸŽ€ JSON::RPC::Legacy::Client πŸŽ€

🌸 METHODS 🌸

  • $client = JSON::RPC::Legacy::Client->new β€” Creates a new JSON::RPC::Legacy::Client object. New client, who dis? πŸ’…
  • $response = $client->call($uri, $procedure_object) β€” Calls to $uri with $procedure_object. The request method is usually "POST". If $uri has a query string, the method is "GET".

About the 'GET' method, see <http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#GetProcedureCall>.

The return value is "JSON::RPC::Legacy::ReturnObject".

  • $client->prepare($uri, $arrayref_of_procedure) β€” Allows you to call methods in the contents of $arrayref_of_procedure. Then you can call the prepared methods with an array reference or a list.

The return value is the result part of JSON::RPC::Legacy::ReturnObject.

$client->prepare($uri, ['sum', 'echo']);

$res = $client->echo('foobar');  # $res is 'foobar'.

$res = $client->sum(10, 20);     # sum up
$res = $client->sum( [10, 20] ); # same as above

If you call a method which is not prepared, it will croak.

Currently, you can’t call any method names that are the same as built-in methods. Noted, bestie. 😭

  • version β€” Sets the JSON-RPC protocol version. 1.1 by default.
  • id β€” Sets a request identifier. In JSON-RPC 1.1, it is optional.

If you set "version" to 1.0 and don’t set id, the module sets 'JSON::RPC::Legacy::Client' to it.

  • ua β€” Setter/getter to the LWP::UserAgent object.
  • json β€” Setter/getter to the JSON coder object. Default is JSON, likes this:
$self->json( JSON->new->allow_nonref->utf8 );

$json = $self->json;

This object serializes/deserializes JSON data. By default, returned JSON data assumes UTF-8 encoded.

  • status_line β€” Returns the status code; after call to a remote procedure, the status code is set.
  • create_json_coder β€” (Class method) Returns a JSON de/encoder in new. You can override it to use your favorite JSON de/encoder.

πŸ“ JSON::RPC::Legacy::ReturnObject πŸ“

The call method or the methods set by prepared return this object. (The returned JSON data is decoded by the JSON coder object which was passed by the client object.)

🧚 METHODS 🧚

  • is_success β€” If the call is successful, returns a true value; otherwise returns a false value.
  • is_error β€” If the call is not successful, returns a true value; otherwise returns a false value.
  • error_message β€” If the response contains an error message, returns it.
  • result β€” Returns the result part of a data structure returned by the called server.
  • content β€” Returns the whole data structure returned by the called server.
  • jsontext β€” Returns the row JSON data.
  • version β€” Returns the version of this response data.

πŸ’œ JSON::RPC::Legacy::ServiceObject πŸ’œ

πŸ‘‘ RESERVED PROCEDURE πŸ‘‘

When a client calls a procedure (method) name 'system.foobar', JSON::RPC::Legacy::Server looks up MyApp::system::foobar.

<http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ProcedureCall>

<http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ServiceDescription>

There is JSON::RPC::Legacy::Server::system::describe for the default response of 'system.describe'.

πŸ”₯ SEE ALSO πŸ”₯

🌈 AUTHOR 🌈

Makamaka Hannyaharamitu, <makamaka[at]cpan.org>.

Copyright 2007-2008 by Makamaka Hannyaharamitu.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that’s the page, bestie 🫢 β€” source/version: perl v5.42.0; date: 2015-08-27; manual slot: JSON::...:Client(3pm). Bye! πŸ’…βœ¨

πŸ“¦ where this page comes from