JSON::...pache2(3pm)
π JSON::RPC::Legacy::Server::Apache2 β a.k.a. JSON::...pache2(3pm) π
okay bestie so real quick: this page comes to you straight from the User Contributed Perl Documentation fam, and today we're talking about the JSON-RPC server for mod_perl2. yes. that one. let's get into it π«Ά
β¨ NAME β¨
JSON::RPC::Legacy::Server::Apache2 β the JSON-RPC sever for mod_perl2 (their spelling, not mine, love them for it π
)
πΈ SYNOPSIS πΈ
so here's the whole vibe. first, in apache conf:
# 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>
and then in your application class:
#--------------------------
# In your application class
package MyApp;
use base qw(JSON::RPC::Legacy::Procedure); # Perl 5.6 or more than
sub echo : Public { # new version style. called by clients
# first argument is JSON::RPC::Legacy::Server object.
return $_[1];
}
sub sum : Public(a:num, b:num) { # sets value into object member a, b.
my ($s, $obj) = @_;
# return a scalar value or a hashref or an arryaref.
return $obj->{a} + $obj->{b};
}
sub a_private_method : Private {
# ... can't be called by client
}
sub sum_old_style { # old version style. taken as Public
my ($s, @arg) = @_;
return $arg[0] + $arg[1];
}
like, that's literally it. you write the subs, the module handles the rest. icon behaviour honestly π
π¦ DESCRIPTION π¦
k so what actually happens under the hood, step by step, no gatekeeping:
- 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 that's the whole loop bestie. Well, you write your procedure code only. the module carries everything else on its back πͺ
π METHODS π
They are inherited from the JSON::RPC::Legacy::Server methods basically. The below methods are implemented in JSON::RPC::Legacy::Server::Apache2.
newβ Creates newJSON::RPC::Legacy::Server::Apache2object. fresh out the box, slay β¨handleβ Runs server object and returns a response.retrieve_json_from_postβ retrieves a JSON request from the body inPOSTmethod.retrieve_json_from_getβ In the protocol v1.1,'GET'request method is also allowable. it retrieves a JSON request from the query string inGETmethod.responseβ returns a response JSON data to a client.
π§ SEE ALSO π§
go read these next, i'm obsessed with all of them fr fr:
JSON::RPC::Legacy::Server,JSON::RPC::Legacy::Procedure,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> β we stan π«Ά
π 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.
ngl the legal bit is short and sweet, but please actually read it before you go redistributing anything, okay? π
and that's a wrap, bestie!! π sending you off with the source/version deets as a little parting gift: this was perl v5.42.0, dated 2015-08-27 πβ¨ bye pookie, go write some Public subs π
π₯
π¦ 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