🖥️
PHP REST API Framework
About this project
A lightweight, fast REST API framework built in pure PHP 8.1. Supports routing, middleware, JWT auth, and auto-validation.
<?php
class Router {
private array $routes = [];
public function get(string $path, callable $handler): void {
$this->routes["GET"][$path] = $handler;
}
public function dispatch(): void {
$method = $_SERVER["REQUEST_METHOD"];
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if (isset($this->routes[$method][$path])) {
call_user_func($this->routes[$method][$path]);
} else {
http_response_code(404);
echo json_encode(["error" => "Not Found"]);
}
}
}
Sign in to leave a comment.
Sign In