Annotated routes for Spiral Framework

v2.8.12 2021-04-28 09:30 UTC


Latest Stable Version Build Status Codecov

Provides the ability to use annotated routes and route groups.


To install the component:

$ composer require spiral/annotated-routes

Activate the bootloader in your application (instead of RouteBootloader):

use Spiral\Router\Bootloader as Router;

// ...

protected const LOAD = [
    // ...
    // ...


Define one or multiple route groups (optional) or configure default group in your bootloader:

namespace App\Bootloader;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Router\GroupRegistry;

class MiddlewareBootloader extends Bootloader
    public function boot(GroupRegistry $registry)

Use environment variable ROUTE_CACHE to enable or disable route caching (by default enabled in non DEBUG mode). To reset route cache:

$ php app.php route:reset


Use the annotation in your controller methods:

namespace App\Controller;

use Spiral\Router\Annotation\Route;

class HomeController
     * @Route(route="/", name="home", methods="GET", group="api")
    public function index()
        return 'Hello World';

Use group attribute to configure middleware and domain core in bulk.


MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.