Download the PHP package zero-to-prod/http-router without Composer
On this page you can find all versions of the php package zero-to-prod/http-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zero-to-prod/http-router
More information about zero-to-prod/http-router
Files in zero-to-prod/http-router
Package http-router
Short Description High-performance HTTP router for PHP with three-level indexing, PSR-15 middleware support, and route caching
License MIT
Homepage https://github.com/zero-to-prod/http-router
Informations about the package http-router
HTTP Router
High-performance HTTP router for PHP 7.2+ with three-level indexing, PSR-15 middleware support, and route caching.
Features
- High Performance: Three-level route indexing for O(1) static route lookup and optimized dynamic route matching
- PSR-15 Middleware: Full support for PSR-15 middleware alongside legacy variadic middleware
- Route Caching: Production-optimized serialization with automatic cache management
- RESTful Resources: Automatic generation of resourceful routes
- Route Groups: Organize routes with shared prefixes and middleware
- Named Routes: Generate URLs from route names with parameter substitution
- Parameter Constraints: Inline (
{id:\d+}) and fluent (where()) constraint syntax - PHP 7.1+ Compatible: Broad multi-version support
Installation
Quick Start
Basic Usage
Defining Routes
Alternative Shorthand:
HTTP Methods
RESTful Resources
Generated routes:
GET /users→index()GET /users/create→create()POST /users→store()GET /users/{id}→show()GET /users/{id}/edit→edit()PUT /users/{id}→update()DELETE /users/{id}→destroy()
Route Groups
Named Routes
Middleware
PSR-15 Middleware
Variadic Middleware
Global Middleware
Route Caching
Fallback Handler
Advanced Usage
Dispatching with Context
Optional Parameters
Multiple Constraints
Wildcard Routes
Action Types
The router supports three types of actions:
Controller Array
Invokable Class
Closure
Note: Closures cannot be cached due to PHP serialization limitations.
Performance
The router uses a three-level indexing strategy for optimal performance:
- Static Index (O(1)): Hash map
method:path→ Route for exact matches - Prefix Index (O(1) + O(n)): Hash map
method:prefix→ [Routes] for common prefixes - Method Index (O(n)): Hash map
method→ [Routes] as fallback
This approach minimizes regex matching for most common routing patterns.
Testing
License
MIT License. See LICENSE for details.
Contributing
Contributions are welcome! Please submit pull requests to the GitHub repository.
Support
- Issues: GitHub Issues
- Email: [email protected]
- Documentation: https://zero-to-prod.github.io/http-router/
Credits
Created and maintained by David Smith.
All versions of http-router with dependencies
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
nyholm/psr7 Version ^1.0
nyholm/psr7-server Version ^1.0