Max Kanat-Alexander


RPC::Any::Server::JSONRPC - A basic JSON-RPC server


 use RPC::Any::Server::JSONRPC;
 # Create a server where calling will call My::Module->bar.
 my $server = RPC::Any::Server::JSONRPC->new(
    dispatch => { 'Foo' => 'My::Module' },
    default_version => '2.0',

 # Read JSON from STDIN and print JSON to STDOUT.
 print $server->handle_input();


This is a server that implements the various JSON-RPC specifications. It supports JSON-RPC 1.0, 1.1, and 2.0. It uses JSON::RPC::Common as its backend for parsing input and producing output, and so it supports everything that that module supports.

This is a basic server that just takes JSON as input to handle_input, and produces JSON as the output from handle_input. It doesn't understand HTTP headers or anything like that, and it doesn't produce HTTP headers. For that, see RPC::Any::Server::JSONRPC::HTTP or RPC::Any::Server::JSONRPC::CGI.

See RPC::Any::Server for a basic description of how servers work in RPC::Any.


These are additional attributes beyond what is specified in RPC::Any::Server that are available for a JSON-RPC server. These can all be specified during new or set like $server->method($value). They are all optional.


This is a string specifying the version to use for error messages in situations where the server doesn't know the JSON-RPC version of the incoming message. (This happens when there is an error parsing the JSON-RPC input--we haven't parsed the input, so we don't know what JSON-RPC version is in use.) This defaults to 2.0 if not specified.


This is a JSON::RPC::Common::Marshal::Text instance that is used to parse incoming JSON and produce output JSON.