Route Patterns
A route pattern is a URL template with optional placeholders. Captured values land on $request->route.
Static segments
Plain text matches literally:
$App->router->get('/about/team', $handler);
Named placeholders
Prefix a segment with : to capture it:
$App->router->get('/users/:id', function($request) use ($App) {
$id = $request->route->id; // string from URL
$App->response(['id' => (int) $id], 'json');
});
Placeholders are always strings. Cast or sanitize before using them — pass through $request->get->int(...)-style helpers if you'd rather rely on the sanitizers, or just (int) at the call site.
Wildcards
* matches the rest of the URL but doesn't capture it:
$App->router->any('/admin/*', $handler); // matches /admin/anything/here
Combine wildcard with a name to capture the trailing segments as a single value:
$App->router->any('/files/*:path', function($request) use ($App) {
$relativePath = $request->route->path; // e.g. "docs/api/v1.pdf"
});
Multiple placeholders
$App->router->get('/blog/:year/:slug', function($request) use ($App) {
$year = $request->route->year;
$slug = $request->route->slug;
});
Order matters
The router runs registered routes top-to-bottom and stops at the first match. Put more specific routes before more permissive ones:
// Wrong order — /users/me would match :id first
$App->router->get('/users/:id', $userHandler);
$App->router->get('/users/me', $meHandler); // unreachable
// Right order
$App->router->get('/users/me', $meHandler);
$App->router->get('/users/:id', $userHandler);