AnyEvent-HTTPD-Router
view release on metacpan or search on metacpan
Routes support http methods, but custom methods
[https://cloud.google.com/apis/design/custom\_methods](https://cloud.google.com/apis/design/custom_methods) can also be used. You
don't need to, of course ;-)
# SYNOPSIS
use AnyEvent::HTTPD::Router;
my $httpd = AnyEvent::HTTPD::Router->new( port => 1337 );
my $all_methods = [qw/GET DELETE HEAD POST PUT PATCH/];
$httpd->reg_routes(
GET => '/index.txt' => sub {
my ( $httpd, $req ) = @_;
$httpd->stop_request;
$req->respond([
200, 'ok', { 'Content-Type' => 'text/plain', }, "test!" ]);
},
$all_methods => '/my-method' => sub {
my ( $httpd, $req ) = @_;
lib/AnyEvent/HTTPD/Router.pm view on Meta::CPAN
my $class = ref($this) || $this;
my %args = @_;
# todo documentation how to overwrite your dispathing
my $dispatcher = delete $args{dispatcher};
my $routes = delete $args{routes};
my $auto_respond_404 = delete $args{auto_respond_404};
my $dispatcher_class = delete $args{dispatcher_class}
|| 'AnyEvent::HTTPD::Router::DefaultDispatcher';
my $known_methods = delete $args{known_methods}
|| [ qw/GET HEAD POST PUT PATCH DELETE TRACE OPTIONS CONNECT/ ];
my $self = $class->SUPER::new(%args);
$self->{known_methods} = $known_methods;
$self->{dispatcher} = defined $dispatcher
? $dispatcher
: $dispatcher_class->new();
$self->reg_cb(
'request' => sub {
lib/AnyEvent/HTTPD/Router.pm view on Meta::CPAN
Routes support http methods, but custom methods
L<https://cloud.google.com/apis/design/custom_methods> can also be used. You
don't need to, of course ;-)
=head1 SYNOPSIS
use AnyEvent::HTTPD::Router;
my $httpd = AnyEvent::HTTPD::Router->new( port => 1337 );
my $all_methods = [qw/GET DELETE HEAD POST PUT PATCH/];
$httpd->reg_routes(
GET => '/index.txt' => sub {
my ( $httpd, $req ) = @_;
$httpd->stop_request;
$req->respond([
200, 'ok', { 'Content-Type' => 'text/plain', }, "test!" ]);
},
$all_methods => '/my-method' => sub {
my ( $httpd, $req ) = @_;
t/06_allowed_methods.t view on Meta::CPAN
is_deeply $httpd->allowed_methods, [qw(GET HEAD POST)], 'initial default routes';
$httpd->{allowed_methods} = [];
is_deeply $httpd->allowed_methods, [], 'removed all methods';
$httpd->reg_routes( ':custom' => '/yada' => sub {} );
is_deeply $httpd->allowed_methods, [qw(GET POST)], 'custom methods use GET or POST';
$httpd->reg_routes( PUT => '/yada' => sub {} );
is_deeply $httpd->allowed_methods, [qw(GET POST PUT)], 'PUT was added';
done_testing;
( run in 0.422 second using v1.01-cache-2.11-cpan-4e96b696675 )