JSON::RPC::Simple - Simple JSON-RPC client and dispatcher (WD 1.1 subset only currently)
As client
use JSON::RPC::Simple; my $client = JSON::RPC::Simple->connect("https://www.example.com/API/", { timeout => 600, }); my $r = $client->echo({ param1 => "value" });
As server:
package MyApp::API; use base qw(JSON::RPC::Simple); sub new { return bless {}, shift }; sub echo : JSONRpcMethod(Arg1, Arg2, Arg3) { my ($self, $request, $args) = @_; } package MyApp::Handler; my $dispatcher = JSON::RPC::Simple->dispatch_to({ "/API" => MyApp::API->new(), "/OtherAPI" => "MyApp::OtherAPI", }); sub handle { my $request = shift; # Assume a HTTP::Request my $response = $dispatcher->handle($request->uri->path, $request); return $response; # Assume a HTTP::Response }
This module is a very simple JSON-RPC 1.1 WD implementation that only supports a subset of the specification.
It supports
This module provides a class method for creating a client that works as a shortcut to JSON::RPC::Simple::Client->new(...).
JSON::RPC::Simple::Client->new(...)
Returns a new client for the given URL with the optional %OPTIONS.
See "options" in JSON::RPC::Simple::Client for what options it accepts.
Claes Jakobsson, <claesjac@cpan.org>
Copyright (C) 2010-2011 by Claes Jakobsson and Glue Finance AB
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install JSON::RPC::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::RPC::Simple
CPAN shell
perl -MCPAN -e shell install JSON::RPC::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.