AnyEvent::JSONRPC::HTTP::Server - Simple HTTP-based JSONRPC server
use AnyEvent::JSONRPC::HTTP::Server; my $server = AnyEvent::JSONRPC::HTTP::Server->new( port => 8080 ); $server->reg_cb( echo => sub { my ($res_cv, @params) = @_; $res_cv->result(@params); }, sum => sub { my ($res_cv, @params) = @_; $res_cv->result( $params[0] + $params[1] ); }, );
This module is server part of AnyEvent::JSONRPC.
Create server object, start listening socket, and return object.
my $server = AnyEvent::JSONRPC::HTTP::Server->new( port => 4423, );
Available %options are:
%options
Bind address. Default to 'localhost'.
If you want to use unix socket, this option should be set to "unix/"
Listening port. Default to '8080'.
Register JSONRPC methods.
$server->reg_cb( echo => sub { my ($res_cv, @params) = @_; $res_cv->result(@params); }, sum => sub { my ($res_cv, @params) = @_; $res_cv->result( $params[0] + $params[1] ); }, );
JSONRPC callback arguments consists of $result_cv, and request @params.
$result_cv
@params
my ($result_cv, @params) = @_;
$result_cv is AnyEvent::JSONRPC::CondVar object. Callback must be call $result_cv->result to return result or $result_cv->error to return error.
$result_cv->result
$result_cv->error
If $result_cv->is_notification() returns true, this is a notify request and the result will not be send to the client.
$result_cv->is_notification()
@params is same as request parameter.
A server based on PSGI/Plack. Quite more flexible than this module.
Peter Makholm <peter@makholm.net>
Copyright (c) 2010 by Peter Makholm.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install AnyEvent::JSONRPC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::JSONRPC
CPAN shell
perl -MCPAN -e shell install AnyEvent::JSONRPC
For more information on module installation, please visit the detailed CPAN module installation guide.