JSON::...:Server(3pm)
πΈ NAME πΈ
okay bestie, this is the manual page for JSON::...:Server(3pm) from User Contributed Perl Documentation π and it's giving:
JSON::RPC::Serverβ Perl implementation of JSON-RPC sever β¨
π SYNOPSIS π
here's the quick-start menu, one vibe per server flavor π
# CGI version
use JSON::RPC::Legacy::Server::CGI;
my $server = JSON::RPC::Legacy::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::Legacy::Server::Apache
PerlSetVar dispatch "MyApp"
PerlSetVar return_die_message 0
</Location>
# Daemon version
use JSON::RPC::Legacy::Server::Daemon;
JSON::RPC::Legacy::Server::Daemon->new(LocalPort => 8080);
->dispatch({'/jsonrpc/API' => 'MyApp'})
->handle();
# FastCGI version
use JSON::RPC::Legacy::Server::FastCGI;
my $server = JSON::RPC::Legacy::Server::FastCGI->new;
$server->dispatch_to('MyApp')->handle();
π¦ DESCRIPTION π¦
okay so the whole flow is literally this, no cap:
- 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.
And then: well, you write your procedure code only. That's the main character energy part π
β¨ METHODS β¨
newβ Creates newJSON::RPC::Legacy::Serverobject. πdispatch($package)/dispatch([$package1, $package1, ...])/dispatch({$path => $package, ...})β Sets your procedure module using package name list or arrayref or hashref. The hashref version is used forpath_infoaccess. πdispatch_toβ An alias todispatch.handleβ Runs server object and returns a response.raise_error(%hash)β Sets an error. An error code number in your procedure is an integer between501and899. Example time:
return $server->raise_error(
code => 501,
message => "This is error in my procedure."
);
jsonβ Setter/Getter to json encoder/decoder object. The default value isJSONobject in the below way:
JSON->new->utf8
In your procedure, changes its behaviour.
$server->json->utf8(0);
The JSON coder creating method is "create_json_coder".
versionβ Setter/Getter to JSON-RPC protocol version used by a client. If version is1.1, returns1.1. Otherwise returns0.charsetβ Setter/Getter to charset. Default is'UTF-8'.content_typeβ Setter/Getter to content type. Default is'application/json'.return_die_messageβ When your program dies in your procedure, sends a return object with error message'Procedure error'by default. If this option is set, uses"die"message.
sub your_procedure {
my ($s) = @_;
$s->return_die_message(1);
die "This is test.";
}
retrieve_json_from_postβ It is used byJSON::RPC::Legacy::Serversubclass.retrieve_json_from_getβ In the protocol v1.1,'GET'request method is also allowable. It is used byJSON::RPC::Legacy::Serversubclass.responseβ It is used byJSON::RPC::Legacy::Serversubclass.requestβ ReturnsHTTP::Requestobject.path_infoβ ReturnsPATH_INFO.max_lengthβ Returns max content-length to your application.translate_error_messageβ Implemented in your subclass. Three arguments (server object, error code and error message) are passed. It must return a message.
sub translate_error_message {
my ($s, $code, $message) = @_;
return $translation_jp_message{$code};
}
create_json_coderβ (Class method) Returns a JSON de/encoder in"new". You can override it to use your favorite JSON de/encode.
π RESERVED PROCEDURE π
When a client call a procedure (method) name 'system.foobar', JSON::RPC::Legacy::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::Legacy::Server::system::describe for default response of 'system.describe'.
π SEE ALSO π
JSON<http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html><http://json-rpc.org/wiki/specification>
π AUTHOR π
Makamaka Hannyaharamitu, <makamaka[at]cpan.org> πΈ
π«Ά COPYRIGHT AND LICENSE π«Ά
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 whole manual, bestie π«Ά this page came from perl v5.42.0, dated 2015-08-27, and it's JSON::...:Server(3pm) β go be iconic with your JSON-RPC server π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-JSON-RPC 1.06-bp160.1.11 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms