Router::Right
Advanced URL router in Raku
Advanced, framework-agnostic URL routing engine for web applications in Raku programming language:
Synopsys
use v6.d;
use Router::Right;
my $route = Router::Right.new;
$route.add(
:name( 'dynaroute' ),
:path( 'GET /dynamic/{id:<[\d]>+}/{tag}/{item}' ),
:payload( 'Dynamic#Route' ),
);
if !(
my %m = $route.match(
%*ENV<REQUEST_URI> || ~(),
)
) {
say $route.error;
}
else {
say %m.gist;
}
Methods
new() ā returns a new Router::Right instance;
add() ā defines a new route;
match() ā attempts to find a route that matches the supplied URL;
error() ā returns the error code of the last failed match;
allowed_methods() ā returns the array of allowed methods for a given route;
url() ā constructs a URL from the route;
as_string() ā returns a report of the defined routes, in order of definition;
with() ā helper method to share information across multiple routes;
resource() ā adds routes to create, read, update, and delete a given resource;
route() ā returns route details hash.
Examples
Hello, world! ā simple router;
Trick with resources ā populate resources with nested with() call;
Wiki pages
Full documentation is available at Router::Right
wiki pages.
License
Router::Right
module is free and open source software, so you can redistribute it and/or modify it under the terms of the Artistic License 2.0.
Author
Please contact me via Matrix or LinkedIn. Your feedback is welcome at narkhov.pro.
Credits
This module was inspired by origin Perl5 Router::Right
developed by @mla. Check it out at Github.