Introduction
Basic routing in FastRoute allows you to define simple routes that respond to HTTP requests. Routes are defined using theRouteCollector object and can execute closures or reference handler functions.
Simple GET Routes
The most basic routes accept a URI and a closure that gets executed when the route is matched:- The root route
/loads the main view - The
/aboutroute loads the about view - Both routes respond only to GET requests
Route Files
Routes are typically organized in separate files:Key Concepts
Route Definition
Use
$r->get(), $r->post(), or other HTTP method helpers to define routesClosures
Routes can execute inline closures for simple logic
Modular Files
Organize routes in separate files and load them in your dispatcher
Clean Syntax
FastRoute provides an intuitive API for route definition
Next Steps
REST API
Build RESTful APIs with multiple HTTP methods
Dynamic Parameters
Use route parameters and regex validation