JSON::RPC::Simple::Dispatcher - Decodes JSON-RPC calls and dispatches them
Instances of this class decodes JSON-RPC calls over HTTP and dispatches them to modules/objects registered for a given path and then encodes the result as in a JSON-RPC format.
Creates a new dispatcher instance. Can take the the following optional named arguments:
The encoder/decoder object to use. Defaults to JSON with utf8 on.
The charset to send in the content-type when creating the response. Defaults to utf-8.
utf-8
A reference to a subroutine which is invoked when an error occurs. May optionally return an object which will be sent as the 'error' member of the result. When called it is passed the request object, the error code, error message, the call ID and target object if any.
This is the HTTP result code. It's reset to 500 (Internal Server Error) each time handle is called. You may change this in your error handling routine.
Gets/sets the json object to use for encoding/decoding
Gets/sets the charset to use when creating the HTTP::Response object.
Gets/sets the error handler to call when an error occurs.
Sets the dispatch table. The dispatch-table is a path to instance mapping where the key is a path and the value the instance of class for which to call the method on. For example
$o->dispatch_to({ "/API" => "MyApp::API", "/Other/API" => MyApp::OtherAPI->new(), });
This method decodes the $request which should be a HTTP::Request look-a-like object and finds the appropriate target in the dispatch table for $path.
The $request object MUST provide the following methods:
The HTTP method of the request such as GET, POST, HEAD, PUT in captial letters.
The Content-Type header from the request.
The Content-Length header from the request.
The content of the request as we only handle POST.
The content is stripped from any unicode BOM before being passed to the JSON decoder.
To install JSON::RPC::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::RPC::Simple
CPAN shell
perl -MCPAN -e shell install JSON::RPC::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.