NAME

PAGI::App::URLMap - Mount apps at URL path prefixes

SYNOPSIS

use PAGI::App::URLMap;

my $map = PAGI::App::URLMap->new;
$map->mount('/api'    => $api_app);
$map->mount('/static' => PAGI::App::File->new(root => $dir));
my $app = $map->to_app;

DESCRIPTION

URLMap routes requests to different apps based on URL path prefix. Longest prefix match wins. The mounted app sees an adjusted path with the prefix removed.

Mount targets and default accept anything "to_app" in PAGI::Utils accepts: a coderef, a component object with a to_app method, or a class name. Mounted apps receive a scope with path stripped of the prefix and root_path extended with it, per the PAGI specification.

OPTIONS

  • default - App (coderef, component object, or class name) to use when no prefix matches

METHODS

mount($prefix, $app)

Mount an app at the given path prefix.

map(\%mapping)

Mount multiple apps from a hashref of prefix => app pairs.