JSON::RPC::Server - Perl implementation of JSON-RPC sever |
JSON::RPC::Server - Perl implementation of JSON-RPC sever
# CGI version use JSON::RPC::Server::CGI; my $server = JSON::RPC::Server::CGI->new;
$server->dispatch_to('MyApp')->handle(); # Apache version # In apache conf PerlRequire /your/path/start.pl PerlModule MyApp <Location /jsonrpc/API> SetHandler perl-script PerlResponseHandler JSON::RPC::Server::Apache PerlSetVar dispatch "MyApp" PerlSetVar return_die_message 0 </Location> # Daemon version use JSON::RPC::Server::Daemon; JSON::RPC::Server::Daemon->new(LocalPort => 8080); ->dispatch({'/jsonrpc/API' => 'MyApp'}) ->handle(); # FastCGI version use JSON::RPC::Server::FastCGI; my $server = JSON::RPC::Server::FastCGI->new; $server->dispatch_to('MyApp')->handle();
Gets a client request.
Parses its JSON data.
Passes the server object and the object decoded from the JSON data to your procedure (method).
Takes your returned value (scalar or arrayref or hashref).
Sends a response.
Well, you write your procedure code only.
dispatch($package)
dispatch
.
raise_error(%hash)
return $server->raise_error( code => 501, message => "This is error in my procedure." );
Sets an error. An error code number in your procedure is an integer between 501 and 899.
JSON->new->utf8
In your procedure, changes its behaviour.
$server->json->utf8(0);
The JSON coder creating method is create_json_coder
.
If this option is set, uses die
message.
sub your_procedure { my ($s) = @_; $s->return_die_message(1); die "This is test."; }
It is used by JSON::RPC::Server subclass.
sub translate_error_message { my ($s, $code, $message) = @_; return $translation_jp_message{$code}; }
new
.
You can override it to use your favorite JSON de/encode.
When a client call a procedure (method) name 'system.foobar', JSON::RPC::Server look 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::Server::system::describe for default response of 'system.describe'.
JSON
http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
http://json-rpc.org/wiki/specification
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.
JSON::RPC::Server - Perl implementation of JSON-RPC sever |