Rand Stats

Router::Right

gitlab:pheix

Router::Right — advanced URL router in Raku

Framework-agnostic URL routing engine for web applications in Raku.

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;
}

Wiki

Full documentation is available on Raku Router::Right wiki pages.

Methods

  1. new() — returns a new Router::Right instance;

  2. add() — defines a new route;

  3. match() — attempts to find a route that matches the supplied path (URL);

  4. error() — returns the error code of the last failed match;

  5. allowed_methods() — returns the array of allowed methods for a given route;

  6. url() — constructs a URL from the route;

  7. as_string() — returns a report of the defined routes, in order of definition;

  8. with() — helper method to share information across multiple routes;

  9. resource() — adds routes to create, read, update, and delete a given resource;

  10. route() — returns route details hash.

Examples

  1. Hello, world! — simple router;

  2. Trick with resources — populate resources with nested with() call;

License

Raku Router::Right is free and opensource software, so you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

Author

Please contact me via LinkedIn or Twitter. Your feedback is welcome at narkhov.pro.

Perl5 Router::Right

Github

Author