Fastpress Router is a simple yet powerful routing class for PHP, part of the Fastpress framework. It allows you to define routes for your application and handle HTTP requests efficiently.
- Supports GET, POST, PUT, and DELETE HTTP methods.
- Easy definition of route patterns.
- Supports RESTful routing.
- Customizable route patterns.
- PHP 7.0 or higher.
Insert instructions for installing this router class or the Fastpress framework.
require 'path/to/Router.php';
$router = new Fastpress\Routing\Router();
// Define a GET route
$router->get('/home', function() {
return 'Welcome to the homepage!';
});
// Handle the request
// Assuming $server and $post are your $_SERVER and $_POST variables
$result = $router->match($server, $post);
if ($result) {
// Route was matched
list($args, $callable) = $result;
call_user_func_array($callable, $args);
} else {
// No route was matched
header("HTTP/1.0 404 Not Found");
}
You can define routes for different HTTP methods:
$router->get($uri, $callable);
$router->post($uri, $callable);
$router->put($uri, $callable);
$router->delete($uri, $callable);
You can use the following placeholders in your route patterns:
- :any - Matches any characters
- :id - Matches numeric characters
- :slug - Matches alphanumeric characters, dashes, and underscores
- :name - Matches alphabetic characters
- :url - Matches alphanumeric characters and URL-friendly symbols
Contributions are welcome! Please feel free to submit a pull request or open issues to improve the library.
This library is open-sourced software licensed under the MIT license.
If you encounter any issues or have questions, please file them in the issues section on GitHub.