Anvyr Docs
Documentation menu Anvyr Loom 1.x
Anvyr Loom

Version 1.x

← All documentation

GuideAnvyr Loom 1.xDeveloper

Routes and middleware

Declare request handlers and follow the middleware pipeline.

On this page

Declare a route

Modules declare a route file in module.json. The file returns a callable that receives the router and application.

<?php

use Anvyr\Loom\Core\Application;
use Anvyr\Loom\Http\Response;
use Anvyr\Loom\Http\Routing\Router;

return static function (Router $router, Application $app): void {
    $router->get('/health', static fn () => Response::json([
        'status' => 'ok',
    ]));
};

The handler can be a callable or a controller array such as [HealthController::class, 'show']. The HTTP entry point loads module routes before the default page routes.

Attach middleware

Use the returned route definition to attach middleware:

$router->post('/messages', [MessageController::class, 'store'])
    ->middleware('csrf')
    ->middleware('throttle');

This is a registration example: provide MessageController in your module before using it. Middleware aliases must be registered in the application. Loom includes session, CSRF, throttling, and response cache middleware.

$router->group(['prefix' => '/api'], function (Router $router): void {
    $router->get('/health', static fn () => Response::json(['status' => 'ok']));
});

Groups can share a prefix and middleware. The default /{slug*} page route handles nested file-backed URLs; your application routes remain explicit.

Inspect the router implementation for parameter matching and dispatch behavior.

Continue readingTenant isolation