Dancer-Plugin-RPC-RESTISH
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
NAME
Dancer::Plugin::RPC::RESTISH - Simple plugin to implement a restish
interface.
SYNOPSIS
In the Controler-bit:
use Dancer::Plugin::RPC::RESTISH;
restish '/endpoint' => {
publish => 'pod',
arguments => ['MyProject::Admin'],
};
and in the Model-bit (MyProject::Admin):
package MyProject::Admin;
=for restish GET@ability/:id rpc_get_ability_details
example/lib/Example.pm view on Meta::CPAN
{
my $system_config = Example::EndpointConfig->new(
publish => 'pod',
bread_board => $system_api,
plugin_arguments => {
arguments => ['Example::API::System'],
},
);
my @plugins = grep { /^RPC::/ } keys %{ config->{plugins} };
for my $plugin (@plugins) {
$system_config->register_endpoint($plugin, '/system');
}
}
{
my $db_config = Example::EndpointConfig->new(
publish => 'config',
bread_board => $db_api,
);
my @plugins = grep { /^RPC::/ } keys %{ config->{plugins} };
for my $plugin (@plugins) {
for my $path (keys %{ config->{plugins}{$plugin} }) {
$db_config->register_endpoint($plugin, $path);
}
}
}
1;
example/lib/Example/EndpointConfig.pm view on Meta::CPAN
service 'Client::MetaCpan' => as (
class => 'Client::MetaCpan',
dependencies => {
base_uri => literal config->{base_uri},
),
};
};
),
);
$config->register_endpoint('RPC::JSONRPC' => '/metacpan');
$config->register_endpoint('RPC::XMLRPC' => '/metacpan');
=head1 ATTRIBUTES
=head2 publish [required]
This attribute can have the value of B<config> or B<pod>, it will be bassed to
L<Dancer::Plugin::RPC>
=head2 callback [optional]
t/225-register-restish.t view on Meta::CPAN
use Dancer::RPCPlugin::CallbackResult;
use Dancer::RPCPlugin::DispatchItem;
use Dancer::RPCPlugin::ErrorResponse;
use Dancer::Test;
{
note("default publish == 'config'");
set(plugins => {
'RPC::RESTISH' => {
'/endpoint' => {
'TestProject::SystemCalls' => {
'GET@ping' => 'do_ping',
'GET@version' => 'do_version',
},
},
}
});
set(encoding => 'utf-8');
restish '/endpoint' => { };
route_exists([GET => '/endpoint/ping'], "GET /endpoint/ping registered");
route_exists([GET => '/endpoint/version'], "GET /endpoint/version registered");
my $response = dancer_response(
GET => '/endpoint/ping',
);
my $ping = from_json('{"response": true}');
if (JSON->VERSION >= 2.90) {
my $t = 1;
$ping->{response} = bless \$t, 'JSON::PP::Boolean';
}
is_deeply(
from_json($response->{content}),
$ping,
"GET /endpoint/ping"
) or diag(explain($response));
}
{
note("publish is code that returns the dispatch-table");
restish '/endpoint2' => {
publish => sub {
eval { require TestProject::SystemCalls; };
error("Cannot load: $@") if $@;
return {
'GET@version' => dispatch_item(
code => TestProject::SystemCalls->can('do_version'),
package => 'TestProject::SystemCalls',
),
};
},
callback => sub { return callback_success(); },
};
route_exists([GET => '/endpoint2/version'], "GET /endpoint2/version registered");
my $response = dancer_response(
GET => '/endpoint2/version',
);
is_deeply(
from_json($response->{content}),
{ software_version => $TestProject::SystemCalls::VERSION },
"GET /endpoint2/version"
);
}
{
note("callback fails");
restish '/fail1' => {
publish => sub {
eval { require TestProject::SystemCalls; };
error("Cannot load: $@") if $@;
return {
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.376 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )