Getting Started
What is Route?
Route is a fast PSR-7 routing and dispatcher package including PSR-15 middleware implementation that enables you to build well designed performant web apps.
At its core is Nikita Popov’s FastRoute package allowing this package to concentrate on the dispatch of your controllers.
Goals
- To provide a “friendlier” API on top of FastRoute.
- To provide an easy interface to implement PSR-7 HTTP messages in to your applications.
- To enable you to implement PSR-15 middleware in to your applications.
- To provide route introspection via the
RouterInterfacefor advanced use cases. - To enable non-blocking route matching with the
match()method. - To provide convenience in building web applications and APIs.
Questions?
Route was created by Phil Bennett. Find him on Twitter at @philipobenito.
Installation
System Requirements
You need PHP >= 8.3.0 to use League\Route but the latest stable version of PHP is recommended.
You will also require an implementation of PSR-7 HTTP Message. Throughout the documentation we will be using the Laminas Diactoros Project, however, there are many implementations to choose from on Packagist.
You may also want to use a PSR-11 dependency injection container and a PSR-17 HTTP factory implementation for enhanced functionality.
Composer
Route is available on Packagist and can be installed using Composer:
composer require league/route
Most modern frameworks will include Composer out of the box, but ensure the following file is included:
<?php
require 'vendor/autoload.php';
Upgrading
If you are upgrading from a previous version of Route, see the upgrade guide.