PHRouter is a simple yet powerful PHP routing library that helps you manage and handle HTTP requests in your web application. It allows you to define routes, apply middleware, and execute custom actions based on the requested URL and HTTP method.
- Define and handle routes for various HTTP methods (GET, POST, PUT, DELETE, etc.).
- Middleware support for common tasks like authentication, logging, and input validation.
- Group routes together and apply middleware to route groups.
- Route parameters with constraints, making it easy to validate and process dynamic parts of URLs.
- Clean and flexible API for building RESTful APIs or web applications.
-
Clone the repository:
git clone https://github.com/koushik/phrouter.git
-
Include the
Router.php
andResponse.php
files in your PHP project. -
Create an instance of the
Router
class and define your routes. -
Start the router to handle incoming requests.
Here's a basic example of how to use PHRouter:
// Include the Router and Response classes
require_once 'Router.php';
require_once 'Response.php';
use PHRouter\Router;
use PHRouter\Response;
// Create a Response object
$response = new Response();
// Create a Router instance
$router = new Router($response);
// Define routes here...
// Start the router
$router->start();
If you'd like to contribute to this project, please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your fork.
- Submit a pull request to the main repository.
This project is licensed under The Unlicense
License - see the LICENSE file for details.
- PHRouter is inspired by various PHP routing libraries and frameworks.
- Special thanks to the PHP community for their contributions and support.