g Callback-results.
=head1 SYNOPSIS
use Dancer2::Plugin::RPC::JSON;
use Dancer2::RPCPlugin::CallbackResultFactory;
jsonrpc '/admin' => {
publish => 'config',
callback =>
package Dancer2::Plugin::RPC::JSONRPC;
use Dancer2::Plugin;
use Moo;
with 'Dancer2::RPCPlugin';
our $VERSION = '2.00';
use constant PLUGIN_NAME => 'jsonrpc';
use Dancer2::RPCPlugin::CallbackResultF
Response;
use Dancer2::RPCPlugin::FlattenData;
use JSON;
use Scalar::Util 'blessed';
use Time::HiRes 'time';
plugin_keywords PLUGIN_NAME;
sub jsonrpc {
my ($plugin, $endpoint, $config) = @_;
$callback = $config->{callback};
$plugin->app->log(debug => "Starting jsonrpc-handler build: ", $lister);
my $jsonrpc_handler = sub {
my ($dsl) = @_;
my $http_request = $dsl
head1 SYNOPSIS
use Dancer2::RPCPlugin::DispatchItem;
use Dancer2::Plugin::RPC::JSON;
jsonrpc '/json' => {
publish => sub {
return {
'system.ping' => Da
ckResultFactory;
use Dancer2::RPCPlugin::ErrorResponse;
use Dancer2::RPCPlugin::FlattenData;
use JSON;
use Scalar::Util 'blessed';
use Time::HiRes 'time';
plugin_keywords PLUGIN_NAME;
sub restrpc {
my ($ct) = (split /;\s*/, $http_request->content_type, 2);
if ($ct ne 'application/json') {
$dsl->pass();
}
$dsl->app->log(
debug => "[handle_res
$dsl->response->content_type('application/json');
my $response;
my $method_args = $http_request->body
? from_json($http_request->body)
: undef;
configming to spec: $@"
=item B<application/json>
If the B<body> is valid JSONRPC (ie. is has a I<'jsonrpc': '2.0'> field/value),
the response is a JSONRPC-error:
code => -32601
message =>
"Method '%s' not found"
If the B<body> is I<not> valid JSONRPC, the response is a generic json struct:
'error': {
'code': -32601,
'message': "Method '$request->path' not found"
elsif ( $content_type eq 'application/json' ) {
content_type('application/json');
my $request = request->body
? from_json(request->body, {allow_nonref => 1})