GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Dancer::Plugin::RPC::RESTRPC(3) User Contributed Perl Documentation Dancer::Plugin::RPC::RESTRPC(3)

Dancer::Plugin::RPC::RESTRPC - RESTRPC Plugin for Dancer

In the Controler-bit:

    use Dancer::Plugin::RPC::RESTRPC;
    restrpc '/base_url' => {
        publish   => 'pod',
        arguments => ['MyProject::Admin']
    };

and in the Model-bit (MyProject::Admin):

    package MyProject::Admin;
    
    =for restrpc rpc_abilities rpc_show_abilities
    
    =cut
    
    sub rpc_show_abilities {
        return {
            # datastructure
        };
    }
    1;

RESTRPC is a simple protocol that uses HTTP-POST to post a JSON-string (with "Content-Type: application/json" to an endpoint. This endpoint is the "base_url" concatenated with the rpc-method name.

This plugin lets one bind a base_url to a set of modules with the new restrpc keyword.

"\%publisher_arguments"
callback => $coderef [optional]
The callback will be called just before the actual rpc-code is called from the dispatch table. The arguments are positional: (full_request, method_name).

    my Dancer::RPCPlugin::CallbackResult $continue = $callback
        ? $callback->(request(), $method_name, @method_args)
        : callback_success();
    

The callback should return a Dancer::RPCPlugin::CallbackResult instance:

  • on_success

        callback_success()
        
  • on_failure

        callback_fail(
            error_code    => <numeric_code>,
            error_message => <error message>
        )
        
code_wrapper => $coderef [optional]
The codewrapper will be called with these positional arguments:
1. $call_coderef
2. $package (where $call_coderef is)
3. $method_name
4. @arguments

The default code_wrapper-sub is:

    sub {
        my $code   = shift;
        my $pkg    = shift;
        my $method = shift;
        $code->(@_);
    };
publisher => <config | pod | \&code_ref>
The publiser key determines the way one connects the rpc-method name with the actual code.
publisher => 'config'
This way of publishing requires you to create a dispatch-table in the app's config YAML:

    plugins:
        "RPC::RESTRPC":
            '/base_url':
                'MyProject::Admin':
                    admin.someFunction: rpc_admin_some_function_name
                'MyProject::User':
                    user.otherFunction: rpc_user_other_function_name
    

The Config-publisher doesn't use the "arguments" value of the %publisher_arguments hash.

publisher => 'pod'
This way of publishing enables one to use a special POD directive "=for restrpc" to connect the rpc-method name to the actual code. The directive must be in the same file as where the code resides.

    =for restrpc admin_someFunction rpc_admin_some_function_name
    

The POD-publisher needs the "arguments" value to be an arrayref with package names in it.

publisher => \&code_ref
This way of publishing requires you to write your own way of building the dispatch-table. The code_ref you supply, gets the "arguments" value of the %publisher_arguments hash.

A dispatch-table looks like:

    return {
        'admin_someFuncion' => dispatch_item(
            package => 'MyProject::Admin',
            code    => MyProject::Admin->can('rpc_admin_some_function_name'),
        ),
        'user_otherFunction' => dispatch_item(
            package => 'MyProject::User',
            code    => MyProject::User->can('rpc_user_other_function_name'),
        ),
    }
    
arguments => <anything>
The value of this key depends on the publisher-method chosen.

This special POD-construct is used for coupling the restrpc-methodname to the actual sub-name in the current package.

Creates a (partial) dispatch table from data passed from the (YAML)-config file.

Creates a (partial) dispatch table from data provided in POD.

(c) MMXVII - Abe Timmerman <abeltje@cpan.org>
2020-12-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.