A simple HTTP Router for Perl6
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore update to new perl6 Dec 26, 2015
.travis.yml add a travis file Oct 17, 2015
META6.json Use SPDX identifier in license field of META6.json Apr 28, 2017
README.md begin converting to use second parameter for $params Nov 1, 2015



A simple, framework-agnostic HTTP Router for Perl6

Build Status


With the HTTP::Easy server:

use v6;
use HTTP::Easy::PSGI;
use HTTP::Router::Blind;

my $http = HTTP::Easy::PSGI.new(:port(8080));
my $router = HTTP::Router::Blind.new();

# simple string-match route
$router.get("/", sub (%env) {
    [200, ['Content-Type' => 'text/plain'], ["Home is where the heart is"]]

$router.get("/about", sub (%env) {
    [200, ['Content-Type' => 'text/plain'], ["About this site"]]

# string match with keyword params,
# the second parameter to the handler function is a hash of params
# extracted from the URL
$router.get("/user/:id", sub (%env, %params) {
    my $user-id = %params<id>;
    [200, ['Content-Type' => 'text/plain'], ["It's user $user-id"]]

# regex match, with named capture-group,
# will match a request like '/items/42253',
# the second parameter to the handler is the Regex match object;
$router.get(/\/items\/$<id>=(.*)/, sub (%env, $params) {
    my $id = $params<id>;
    [200, ['Content-Type' => 'text/plain'], ["got request for item $id"]]

# you can pass multiple handler functions
# which will be chained together in order
sub do-something-special (%env) { ...; return %env; }
$router.get('/secret', &do-something-special, sub (%env) {
    [200, ['Content-Type' => 'text/plain'], ["it's a secret"]]

# in our app function, we just call $router.dispatch
my $app = sub (%env) {
    $router.dispatch(%env<REQUEST_METHOD>, %env<REQUEST_URI>, %env);



  • 2.0.0 : for keyword and regex matches, pass the matched params as a second parameter to the handler function, instead of setting %env<params>.